Skip to main content

ReconstructionService

ReconstructionService defines the primary interface responsible for reconstructing files from their chunks, either on disk or as a stream.
This service communicates directly with a ChunkSource to obtain the required data and reassemble the file.

It serves as the core component of the restoration process within rac-delta.


Methods

MethodReturnsDescription
reconstructFile(entry, outputPath, chunkSource, options?)Promise<void>Reconstruct a single file in disk.
reconstructAll(plan, outputDir, chunkSource, options?)Promise<void>Reconstruct all files from a DeltaPlan in disk.
reconstructToStream(entry, chunkSource)Promise<Readable>Reconstruct a file in memory and returns it as a Readable stream.

ReconstructionOptions

Options for the reconstruction progress:

export interface ReconstructionOptions {
forceRebuild?: boolean;
verifyAfterRebuild?: boolean;
inPlaceReconstructionThreshold?: number;
fileConcurrency?: number;
onProgress?: (
reconstructProgress: number,
diskSpeed: number,
networkProgress?: number,
networkSpeed?: number
) => void;
}
ParameterTypeDescription
forceRebuildbooleanForce to rebuild even if hash file matches.
verifyAfterRebuildbooleanVerifies the reconstructed file hash after finishing. If hash does not match, an error is thrown.
inPlaceReconstructionThresholdnumberMinimum file size (in bytes) required to perform an in-place reconstruction instead of using a temporary file.
fileConcurrencynumberHow many files will reconstruct concurrently (default value is 5).
onProgressbooleanCallback that returns disk usage and optional network speed (only for storage chunk sources via streaming download-reconstruction).

Method Details

reconstructFile(entry, outputPath, chunkSource, options?)

Reconstruct a single file from a FileEntry in disk.

Parameters:

NameTypeDescription
entryFileEntryThe FileEntry containing the list of chunks and path of the file.
outputPathstringThe path where the file will be reconstructed.
chunkSourceChunkSourceThe chunk source implementation where the chunks will be retrieved.
options?ReconstructionOptionsOptions for reconstruction.

Returns: Promise<void>


reconstructAll(plan, outputDir, chunkSource, options?)

Reconstruct all files from given DeltaPlan in disk.

Parameters:

NameTypeDescription
planDeltaPlanThe DeltaPlan containing the files to be reconstructed.
outputDirstringThe path where the files will be reconstructed.
chunkSourceChunkSourceThe chunk source implementation where the chunks will be retrieved.
options?ReconstructionOptionsOptions for reconstruction.

Returns: Promise<void>


reconstructToStream(entry, chunkSource)

Reconstruct a file in memory and returns it as a Readable stream.

Parameters:

NameTypeDescription
entryFileEntryThe FileEntry containing the list of chunks and path of the file.
chunkSourceChunkSourceThe chunk source implementation where the chunks will be retrieved.

Returns: Promise<void>