Expand description
File splitting and joining for arbitrary-size data.
Joining is async; splitting is CPU-bound and runs on rayon. Splitter
implements Write for streaming producers.
§Store-centric API (extension traits)
use futures::executor::block_on;
use nectar_primitives::file::{ChunkGetExt, ChunkPutExt};
use nectar_primitives::store::MemoryStore;
use nectar_primitives::DEFAULT_BODY_SIZE;
let store = MemoryStore::<DEFAULT_BODY_SIZE>::new();
let addr = block_on(store.write_file(b"hello swarm".to_vec())).unwrap();
let data = block_on(store.read_file(addr)).unwrap();
assert_eq!(data, b"hello swarm");§Free function API
use futures::executor::block_on;
use nectar_primitives::file::{split, join};
use nectar_primitives::DEFAULT_BODY_SIZE;
let data = b"Hello, Swarm!";
let (root, store) = split::<DEFAULT_BODY_SIZE>(data).unwrap();
let recovered = block_on(join(&store, root)).unwrap();
assert_eq!(recovered, data);§Encrypted split and join
use futures::executor::block_on;
use nectar_primitives::file::{split_encrypted, join};
use nectar_primitives::DEFAULT_BODY_SIZE;
let data = b"secret data";
let (root_ref, store) = split_encrypted::<DEFAULT_BODY_SIZE>(data).unwrap();
let recovered = block_on(join(&store, root_ref)).unwrap();
assert_eq!(recovered, data);Re-exports§
Modules§
- entry_
ref - Unified file entry reference type.
- error
- Error types for file splitting and joining operations.
- mode
- Chunk mode traits for plain and encrypted file operations.
Structs§
- Chunk
Range - Range of chunk indices.
- Generic
Joiner - Generic async joiner parameterized by chunk mode.
- Joiner
Reader - Wrapper providing
tokio::io::AsyncReadover aGenericJoiner. - Tree
Params - Tree structure for a file of known size.
- Windowed
Joiner Reader - Native
AsyncRead+AsyncSeekshim, drainingWindowedReader::streaminto a residual buffer. - Windowed
Reader - Seek-and-play reader: forward in-order delivery over a window that slides
with the read cursor, bounded to
windowin-flight plus buffered leaves.
Traits§
- Chunk
GetExt - Extension methods for async chunk getters.
- Chunk
PutExt - Extension methods for chunk putters.
- JoinRef
- Maps a reference type to its join mode.
Sealed; implemented for
ChunkAddressandEncryptedChunkRef. - ReadAt
- Sync data source supporting offset-based reads.
- WriteAt
- Async random-access write sink. Each leaf body is written at its absolute
offset; when every offset is written the sink is whole. Not
Send-bound so a single-threaded browser writable can implement it.
Functions§
- join
- Join chunks asynchronously. Dispatches plain/encrypted via
JoinRef. - split
- Split data into chunks, returning root address and chunk store.
- split_
encrypted - Split data into encrypted chunks.
Type Aliases§
- Encrypted
Joiner - Encrypted async joiner.
- Encrypted
Parallel Splitter - Encrypted parallel splitter.
- Encrypted
Splitter - Encrypted file splitter.
- Joiner
- Plain (unencrypted) async joiner.
- Parallel
Splitter - Plain (unencrypted) parallel splitter.
- Splitter
- Plain (unencrypted) file splitter.