blob

Crates.ioblob
lib.rsblob
version0.2.1
sourcesrc
created_at2017-02-04 09:12:02.147094
updated_at2019-01-22 13:34:48.601382
descriptionBlob serialization/deserialization utilities
homepage
repositoryhttps://github.com/novacrazy/blob-rs
max_upload_size
id8377
size10,279
Nova (novacrazy)

documentation

https://docs.rs/blob/

README

blob

This crate provides a simple Blob structure for use in converting binary data to/from a human-readable form using the serde library.

When serializing, it will encode the binary data as base-64, and when deserializing it can either read a base-64 encoded string or a sequence of 8-bit integers.

In essence, Blob is just a wrapper around a Vec<u8> with custom serialization functionality.

Additionally, thanks to Rust's wonderful conversion system, any type which can be converted into a Vec<u8> can be converted into a Blob

For example, to create an empty blob with space allocated:

extern crate blob;

use blob::Blob;

fn main() {
    let my_blob = Blob::from(Vec::with_capacity(100));

    assert_eq!(my_blob.capacity(), 100);
}

Additionally, blobs can be created directly from base-64 encoded strings either via the decode_base64 associated function or via the FromStr trait

For example:

extern crate blob;

use std::str::FromStr;

use blob::Blob;

fn main() {
    let my_blob = Blob::from_str("AQIDBAU=").unwrap();

    assert_eq!(my_blob, [1, 2, 3, 4, 5]);
}
Other semi-related usage notes:

Since the Blob is expected to contain binary data, you may want to convert it into other forms.

After deserialization, into_vec can be called to retrieve the inner vector of data, and that can be fed into std::io::Cursor to create an io::Read+io::Seek reader.

Commit count: 9

cargo fmt