#vlq #encode #codec #next #j

no-std dev blobby

Iterator over simple binary blob storage

6 releases

0.3.1 Dec 7, 2021
0.3.0 Jul 1, 2020
0.2.0 Jun 13, 2020
0.1.2 Jan 28, 2019
0.1.1 Sep 26, 2018

#76 in No standard library

Download history 4364/week @ 2023-10-27 1932/week @ 2023-11-03 6569/week @ 2023-11-10 3873/week @ 2023-11-17 1826/week @ 2023-11-24 1426/week @ 2023-12-01 1378/week @ 2023-12-08 1908/week @ 2023-12-15 869/week @ 2023-12-22 3075/week @ 2023-12-29 13829/week @ 2024-01-05 3866/week @ 2024-01-12 2622/week @ 2024-01-19 3479/week @ 2024-01-26 1498/week @ 2024-02-02 1910/week @ 2024-02-09

9,871 downloads per month
Used in 102 crates (15 directly)

MIT/Apache

14KB
273 lines

Iterators over a simple binary blob storage.

Storage format

Storage format represents a sequence of binary blobs. The format uses git-flavored variable-length quantity (VLQ) for encoding unsigned numbers.

File starts with a number of de-duplicated blobs d. It followed by d entries. Each entry starts with an integer m, immediately folowed by m bytes representing de-duplicated binary blob.

Next follows unspecified number of entries representing sequence of stored blobs. Each entry starts with an unsigned integer n. The least significant bit of this integer is used as a flag. If the flag is equal to 0, then the number is followed by n >> 1 bytes, representing a stored binary blob. Otherwise the entry references a de-duplicated entry number n >> 1.

Examples

let buf = b"\x02\x05hello\x06world!\x01\x02 \x00\x03\x06:::\x03\x01\x00";
let mut v = blobby::BlobIterator::new(buf).unwrap();
assert_eq!(v.next(), Some(Ok(&b"hello"[..])));
assert_eq!(v.next(), Some(Ok(&b" "[..])));
assert_eq!(v.next(), Some(Ok(&b""[..])));
assert_eq!(v.next(), Some(Ok(&b"world!"[..])));
assert_eq!(v.next(), Some(Ok(&b":::"[..])));
assert_eq!(v.next(), Some(Ok(&b"world!"[..])));
assert_eq!(v.next(), Some(Ok(&b"hello"[..])));
assert_eq!(v.next(), Some(Ok(&b""[..])));
assert_eq!(v.next(), None);

let mut v = blobby::Blob2Iterator::new(buf).unwrap();
assert_eq!(v.next(), Some(Ok([&b"hello"[..], b" "])));
assert_eq!(v.next(), Some(Ok([&b""[..], b"world!"])));
assert_eq!(v.next(), Some(Ok([&b":::"[..], b"world!"])));
assert_eq!(v.next(), Some(Ok([&b"hello"[..], b""])));
assert_eq!(v.next(), None);

let mut v = blobby::Blob4Iterator::new(buf).unwrap();
assert_eq!(v.next(), Some(Ok([&b"hello"[..], b" ", b"", b"world!"])));
assert_eq!(v.next(), Some(Ok([&b":::"[..], b"world!", b"hello", b""])));
assert_eq!(v.next(), None);

No runtime deps