Struct bc_components::Compressed
source · pub struct Compressed { /* private fields */ }
Expand description
A compressed binary object.
Implemented using the raw DEFLATE format as described in IETF RFC 1951.
The following obtains the equivalent configuration of the encoder:
deflateInit2(zstream,5,Z_DEFLATED,-15,8,Z_DEFAULT_STRATEGY)
If the payload is too small to compress, the uncompressed payload is placed in
the compressedData
field and the size of that field will be the same as the
uncompressedSize
field.
Implementations§
source§impl Compressed
impl Compressed
sourcepub fn new(
checksum: u32,
uncompressed_size: usize,
compressed_data: Vec<u8>,
digest: Option<Digest>
) -> Option<Self>
pub fn new( checksum: u32, uncompressed_size: usize, compressed_data: Vec<u8>, digest: Option<Digest> ) -> Option<Self>
Creates a new Compressed
object with the given checksum, uncompressed size, compressed data, and digest.
This is a low-level function that does not check the validity of the compressed data.
Returns None
if the compressed data is larger than the uncompressed size.
sourcepub fn from_uncompressed_data<T>(
uncompressed_data: T,
digest: Option<Digest>
) -> Selfwhere
T: AsRef<[u8]>,
pub fn from_uncompressed_data<T>( uncompressed_data: T, digest: Option<Digest> ) -> Selfwhere T: AsRef<[u8]>,
Creates a new Compressed
object from the given uncompressed data and digest.
The uncompressed data is compressed using the DEFLATE format with a compression level of 6.
If the compressed data is smaller than the uncompressed data, the compressed data is stored in the compressed_data
field.
Otherwise, the uncompressed data is stored in the compressed_data
field.
sourcepub fn uncompress(&self) -> Result<Vec<u8>, CompressedError>
pub fn uncompress(&self) -> Result<Vec<u8>, CompressedError>
Uncompresses the compressed data and returns the uncompressed data.
Returns an error if the compressed data is corrupt or the checksum does not match the uncompressed data.
sourcepub fn compressed_size(&self) -> usize
pub fn compressed_size(&self) -> usize
Returns the size of the compressed data.
sourcepub fn compression_ratio(&self) -> f64
pub fn compression_ratio(&self) -> f64
Returns the compression ratio of the compressed data.
sourcepub fn digest_ref_opt(&self) -> Option<&Digest>
pub fn digest_ref_opt(&self) -> Option<&Digest>
Returns a reference to the digest of the compressed data, if it exists.
sourcepub fn has_digest(&self) -> bool
pub fn has_digest(&self) -> bool
Returns true
if the compressed data has a digest.
Trait Implementations§
source§impl CBORDecodable for Compressed
impl CBORDecodable for Compressed
source§impl CBOREncodable for Compressed
impl CBOREncodable for Compressed
source§impl CBORTagged for Compressed
impl CBORTagged for Compressed
source§impl CBORTaggedDecodable for Compressed
impl CBORTaggedDecodable for Compressed
source§fn from_untagged_cbor(cbor: &CBOR) -> Result<Self, Error>
fn from_untagged_cbor(cbor: &CBOR) -> Result<Self, Error>
source§fn from_tagged_cbor(cbor: &CBOR) -> Result<Self, Error>where
Self: Sized,
fn from_tagged_cbor(cbor: &CBOR) -> Result<Self, Error>where Self: Sized,
source§impl CBORTaggedEncodable for Compressed
impl CBORTaggedEncodable for Compressed
source§fn untagged_cbor(&self) -> CBOR
fn untagged_cbor(&self) -> CBOR
source§fn tagged_cbor(&self) -> CBOR
fn tagged_cbor(&self) -> CBOR
source§impl Clone for Compressed
impl Clone for Compressed
source§fn clone(&self) -> Compressed
fn clone(&self) -> Compressed
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for Compressed
impl Debug for Compressed
source§impl DigestProvider for Compressed
impl DigestProvider for Compressed
source§impl PartialEq<Compressed> for Compressed
impl PartialEq<Compressed> for Compressed
source§fn eq(&self, other: &Compressed) -> bool
fn eq(&self, other: &Compressed) -> bool
self
and other
values to be equal, and is used
by ==
.