pub struct BufferedSink<Writer = AEADWriter, Buffer = BlockBuffer> { /* private fields */ }
Expand description
Buffered object writer that supports std::io::Write
.
Due to performance and storage waste considerations, this will generate a new chunk roughly about every 500kB of the input stream.
You need to take this into account when you want to create the
indexes around the stream, as every ChunkPointer
is 88 bytes
in size, which will occupy memory and storage.
Note that you can’t std::io::Seek
in this stream at this point
when reading it.
§Examples
use std::io::Write;
use infinitree::{*, crypto::UsernamePassword, fields::Serialized, backends::test::InMemoryBackend, object::{Stream, BufferedSink}};
let mut tree = Infinitree::<infinitree::fields::VersionedMap<String, Stream>>::empty(
InMemoryBackend::shared(),
UsernamePassword::with_credentials("username".to_string(), "password".to_string()).unwrap()
).unwrap();
let mut sink = BufferedSink::new(tree.storage_writer().unwrap());
sink.write(b"it's going in the sink");
tree.index().insert("message_1".to_string(), sink.finish().unwrap());
tree.commit(None);
Implementations§
Source§impl<W> BufferedSink<W>where
W: Writer,
impl<W> BufferedSink<W>where
W: Writer,
Sourcepub fn new(writer: W) -> BufferedSink<W> ⓘ
pub fn new(writer: W) -> BufferedSink<W> ⓘ
Create a new BufferedSink
with the underlying
Writer
instance.
Sourcepub fn with_chunk_size(writer: W, chunk_size: usize) -> Self
pub fn with_chunk_size(writer: W, chunk_size: usize) -> Self
Create a new BufferedSink
with a custom chunk size
The default chunk size is 500 * 1024
bytes, which
experientially is a good trade-off for various stream sizes,
as it will minimize storage overhead.
Source§impl<W, Buffer> BufferedSink<W, Buffer>
impl<W, Buffer> BufferedSink<W, Buffer>
Sourcepub fn with_buffer(writer: W, buffer: Buffer) -> Result<Self>
pub fn with_buffer(writer: W, buffer: Buffer) -> Result<Self>
Create a new BufferedSink
with the underlying
Writer
and buffer.
Sourcepub fn set_chunk_size(self, size: usize) -> Result<Self>
pub fn set_chunk_size(self, size: usize) -> Result<Self>
Set the maximum size for chunks.
§Errors
Will return an error if the underlying buffer is too small.
Sourcepub fn chunk_size(&self) -> usize
pub fn chunk_size(&self) -> usize
Return the current effective maximum chunk size.
Trait Implementations§
Source§impl<W, Buffer> Write for BufferedSink<W, Buffer>
impl<W, Buffer> Write for BufferedSink<W, Buffer>
Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector
)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored
)Auto Trait Implementations§
impl<Writer, Buffer> Freeze for BufferedSink<Writer, Buffer>
impl<Writer, Buffer> RefUnwindSafe for BufferedSink<Writer, Buffer>where
Writer: RefUnwindSafe,
Buffer: RefUnwindSafe,
impl<Writer, Buffer> Send for BufferedSink<Writer, Buffer>
impl<Writer, Buffer> Sync for BufferedSink<Writer, Buffer>
impl<Writer, Buffer> Unpin for BufferedSink<Writer, Buffer>
impl<Writer, Buffer> UnwindSafe for BufferedSink<Writer, Buffer>where
Writer: UnwindSafe,
Buffer: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FieldWriter for T
impl<T> FieldWriter for T
Source§fn write_next(&mut self, obj: impl Serialize + Send)
fn write_next(&mut self, obj: impl Serialize + Send)
obj
into the index