Skip to main content

Module file

Module file 

Source
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§

pub use entry_ref::EntryRef;
pub use error::FileError;

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§

ChunkRange
Range of chunk indices.
GenericJoiner
Generic async joiner parameterized by chunk mode.
JoinerReader
Wrapper providing tokio::io::AsyncRead over a GenericJoiner.
TreeParams
Tree structure for a file of known size.
WindowedJoinerReader
Native AsyncRead + AsyncSeek shim, draining WindowedReader::stream into a residual buffer.
WindowedReader
Seek-and-play reader: forward in-order delivery over a window that slides with the read cursor, bounded to window in-flight plus buffered leaves.

Traits§

ChunkGetExt
Extension methods for async chunk getters.
ChunkPutExt
Extension methods for chunk putters.
JoinRef
Maps a reference type to its join mode. Sealed; implemented for ChunkAddress and EncryptedChunkRef.
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§

EncryptedJoiner
Encrypted async joiner.
EncryptedParallelSplitter
Encrypted parallel splitter.
EncryptedSplitter
Encrypted file splitter.
Joiner
Plain (unencrypted) async joiner.
ParallelSplitter
Plain (unencrypted) parallel splitter.
Splitter
Plain (unencrypted) file splitter.