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§

Create a new BufferedSink with the underlying Writer instance.

Create a new BufferedSink with the underlying Writer and buffer.

Clear the internal buffer without flushing the underlying Writer.

Calling clear() over finish allows re-using the same buffer and avoids fragmenting data written to storage.

Returns the stream’s descriptor which can be freely serialized or used in an index.

Finish using the BufferedSink instance, flush and close the underlying Writer.

Returns the stream’s descriptor which can be freely serialized or used in an index.

Trait Implementations§

Write a buffer into this writer, returning how many bytes were written. Read more
Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
Like write, except that it writes from a slice of buffers. Read more
🔬This is a nightly-only experimental API. (can_vector)
Determines if this Writer has an efficient write_vectored implementation. Read more
Attempts to write an entire buffer into this writer. Read more
🔬This is a nightly-only experimental API. (write_all_vectored)
Attempts to write multiple buffers into this writer. Read more
Writes a formatted string into this writer, returning any error encountered. Read more
Creates a “by reference” adapter for this instance of Write. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Write the next obj into the index

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Write a slice of bytes to the underlying stream Read more
Write a single byte to this stream
Should always be Self
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Writes an unsigned 8 bit integer to the underlying writer. Read more
Writes a signed 8 bit integer to the underlying writer. Read more
Writes an unsigned 16 bit integer to the underlying writer. Read more
Writes a signed 16 bit integer to the underlying writer. Read more
Writes an unsigned 24 bit integer to the underlying writer. Read more
Writes a signed 24 bit integer to the underlying writer. Read more
Writes an unsigned 32 bit integer to the underlying writer. Read more
Writes a signed 32 bit integer to the underlying writer. Read more
Writes an unsigned 48 bit integer to the underlying writer. Read more
Writes a signed 48 bit integer to the underlying writer. Read more
Writes an unsigned 64 bit integer to the underlying writer. Read more
Writes a signed 64 bit integer to the underlying writer. Read more
Writes an unsigned 128 bit integer to the underlying writer.
Writes a signed 128 bit integer to the underlying writer.
Writes an unsigned n-bytes integer to the underlying writer. Read more
Writes a signed n-bytes integer to the underlying writer. Read more
Writes an unsigned n-bytes integer to the underlying writer. Read more
Writes a signed n-bytes integer to the underlying writer. Read more
Writes a IEEE754 single-precision (4 bytes) floating point number to the underlying writer. Read more
Writes a IEEE754 double-precision (8 bytes) floating point number to the underlying writer. Read more