Skip to main content

DeltaService

DeltaService provides methods to generate RDIndex objects from directories or streams, compare two index, and generate a DeltaPlan describing which chunks need to be uploaded, downloaded, or removed.

Internally, it relies on HasherService to hash files and streams.


Methods

MethodReturnsDescription
createIndexFromDirectory(rootPath, chunkSize, concurrency?, ignorePatterns?)Promise<RDIndex>Scans a directory, splits files into chunks, hashes them, and returns an RDIndex.
createFileEntryFromStream(stream, path)Promise<FileEntry>Creates a FileEntry from an async chunk stream.
compare(source, target)DeltaPlanCompares two rd-index and returns a delta plan describing missing, reused, and obsolete chunks.
mergePlans(base, updates)DeltaPlanMerges two delta plans
compareForUpload(localIndex, remoteIndex)Promise<DeltaPlan>Prepares delta plan for uploading changes
compareForDownload(localIndex, remoteIndex)Promise<DeltaPlan>Prepares delta plan for downloading

Method Details

createIndexFromDirectory(rootPath, chunkSize, concurrency?, ignorePatterns?)

Generates an RDIndex for a directory. Splits files into chunks and hashes them.

Parameters:

NameTypeDescription
rootPathstringDirectory to scan recursively
chunkSizenumberSize of chunks in bytes (recommended 1MB)
concurrencynumber?Optional max number of parallel operations
ignorePatternsstring[]?Optional glob patterns to ignore

Returns: Promise<RDIndex>

Notes: Uses HasherService.hashStream internally.


createFileEntryFromStream(stream, path)

Creates a FileEntry from a valid stream of chunks (from a file).

Parameters:

ParameterTypeDescription
streamAsyncChunkStreamInput async chunk stream
pathstringRelative path of the file
export interface AsyncChunkStream extends AsyncIterable<Uint8Array> {
nextChunk(): Promise<Uint8Array | null>;
reset?(): Promise<void>;
close?(): Promise<void>;
}

Returns: Promise<FileEntry>

Notes: Hashes chunks with HasherService to produce a compatible FileEntry.


compare(source, target)

Compares two rd-index to generate a DeltaPlan.

Parameters:

ParameterTypeDescription
sourceRDIndexSource index
targetRDIndex | nullTarget index (can be null)

Returns: DeltaPlan


mergePlans(base, updates)

Merges two delta plans into one.

Parameters:

ParameterTypeDescription
baseDeltaPlanBase delta plan to merge
updatesDeltaPlanUpdates delta plan to merge

Returns: DeltaPlan


compareForUpload(localIndex, remoteIndex)

Wrapper to generate a delta plan ready for uploading files.

Parameters:

ParameterTypeDescription
localIndexRDIndexLocal rd-index
remoteIndexRDIndex | nullRemote rd-index

Returns: Promise<DeltaPlan>


compareForDownload(localIndex, remoteIndex)

Wrapper to generate a delta plan ready for downloading files.

Parameters:

ParameterTypeDescription
localIndexRDIndex | nullLocal rd-index
remoteIndexRDIndexRemote rd-index

Returns: Promise<DeltaPlan>