summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ripple/fossil/src/lib.rs33
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()
 	}
 }