diff options
author | edef <edef@unfathomable.blue> | 2022-04-25 00:18:39 +0000 |
---|---|---|
committer | edef <edef@unfathomable.blue> | 2022-04-25 00:18:39 +0000 |
commit | 9222c127fc7c5af62a64dd5cf0fa46c42783d990 (patch) | |
tree | 22a0a66f21cb8653f553baf70597036c2c5e5165 | |
parent | 2d1c796947dff6370dc5de27abdc789c1f9dd338 (diff) | |
download | unf-legacy-9222c127fc7c5af62a64dd5cf0fa46c42783d990.tar.zst |
ripple/fossil: implement incremental blob reading
Change-Id: I69ae53824e149133aa6bb61dda201f972c840b1f
-rw-r--r-- | ripple/fossil/src/lib.rs | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/ripple/fossil/src/lib.rs b/ripple/fossil/src/lib.rs index 4c747e8..ed55138 100644 --- a/ripple/fossil/src/lib.rs +++ b/ripple/fossil/src/lib.rs @@ -157,6 +157,12 @@ impl Store { } pub fn read_blob(&self, ident: Digest) -> Vec<u8> { + let mut buffer = Vec::new(); + self.open_blob(ident).read_to_end(&mut buffer).unwrap(); + buffer + } + + pub fn open_blob(&self, ident: Digest) -> Blob { let buf = self .db .get(&*ident.as_bytes()) @@ -169,7 +175,7 @@ impl Store { bao_inline, } = store::Blob::decode(&*buf).unwrap(); - let mut blob = bao::decode::Decoder::new_outboard( + Blob(bao::decode::Decoder::new_outboard( RawBlob { store: self, slice: Slice { offset, length }, @@ -177,12 +183,29 @@ impl Store { }, io::Cursor::new(bao_inline), &ident, - ); + )) + } +} - let mut buffer = Vec::new(); - blob.read_to_end(&mut buffer).unwrap(); +pub struct Blob<'a>(bao::decode::Decoder<RawBlob<'a>, std::io::Cursor<Vec<u8>>>); - buffer +impl io::Read for Blob<'_> { + fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { + self.0.read(buf) + } +} + +impl io::Seek for Blob<'_> { + fn seek(&mut self, pos: io::SeekFrom) -> io::Result<u64> { + self.0.seek(pos) + } + + fn rewind(&mut self) -> io::Result<()> { + self.0.rewind() + } + + fn stream_position(&mut self) -> io::Result<u64> { + self.0.stream_position() } } |