Skip to main content

Module file

Module file 

Source
Expand description

File splitting and joining for arbitrary-size data.

Async is the primary API. SyncJoiner implements Read + Seek, SyncSplitter implements Write.

§Store-centric API (extension traits)

use nectar_primitives::file::{SyncChunkGetExt, SyncChunkPutExt};
use nectar_primitives::store::MemoryStore;
use nectar_primitives::DEFAULT_BODY_SIZE;

let store = MemoryStore::<DEFAULT_BODY_SIZE>::new();
let addr = store.write_file(b"hello swarm").unwrap();
let data = store.read_file(addr).unwrap();
assert_eq!(data, b"hello swarm");

§Free function API

use nectar_primitives::file::{sync_split, sync_join};
use nectar_primitives::DEFAULT_BODY_SIZE;

let data = b"Hello, Swarm!";
let (root, store) = sync_split::<DEFAULT_BODY_SIZE>(data).unwrap();
let recovered = sync_join(&store, root).unwrap();
assert_eq!(recovered, data);

§Encrypted split and join

use nectar_primitives::file::{sync_split_encrypted, sync_join};
use nectar_primitives::DEFAULT_BODY_SIZE;

let data = b"secret data";
let (root_ref, store) = sync_split_encrypted::<DEFAULT_BODY_SIZE>(data).unwrap();
let recovered = sync_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.
GenericSyncJoiner
Generic joiner parameterized by chunk mode.
JoinerReader
Wrapper providing tokio::io::AsyncRead over a GenericJoiner.
TreeParams
Tree structure for a file of known size.

Traits§

ChunkGetExt
Extension methods for async chunk getters.
JoinRef
Maps a reference type to its join mode. Sealed — implemented for ChunkAddress and EncryptedChunkRef.
SyncChunkGetExt
Extension methods for sync chunk getters.
SyncChunkPutExt
Extension methods for sync chunk putters.
SyncReadAt
Sync data source supporting offset-based reads.

Functions§

join
Join chunks asynchronously. Dispatches plain/encrypted via JoinRef.
sync_join
Join chunks synchronously. Dispatches plain/encrypted via JoinRef.
sync_split
Split data into chunks synchronously, returning root address and chunk store.
sync_split_encrypted
Split data into encrypted chunks synchronously.

Type Aliases§

EncryptedJoiner
Encrypted async joiner.
EncryptedSyncJoiner
Encrypted file joiner.
EncryptedSyncParallelSplitter
Encrypted parallel splitter.
EncryptedSyncSplitter
Encrypted file splitter.
Joiner
Plain (unencrypted) async joiner.
SyncJoiner
Plain (unencrypted) file joiner.
SyncParallelSplitter
Plain (unencrypted) parallel splitter.
SyncSplitter
Plain (unencrypted) file splitter.