Skip to main content

HashStorageAdapter

HashStorageAdapter defines the contract for any storage backend that stores chunks identified by hash.
It extends StorageAdapter.

This class is abstract; real implementations belong to the infrastructure layer and are not used directly by consumers of the SDK.


Properties

NameTypeDescription
type"hash"Identifies the adapter category.

Methods

MethodReturnsDescription
getChunk(hash)Promise<Readable | null>Retrieve a chunk stream by its hash.
putChunk(hash, data, opts?)Promise<void>Upload a chunk from a readable stream.
chunkExists(hash)Promise<boolean>Check whether a chunk exists.
deleteChunk(hash)Promise<void>Delete a chunk.
listChunks?()Promise<string[]>Optional: list stored chunk hashes.
getChunkInfo?(hash)Promise<BlobInfo | null>Optional: return chunk metadata.
getRemoteIndex()Promise<RDIndex | null>Retrieve remote rd-index.json
putRemoteIndex(index)Promise<void>Upload remote rd-index.json

Method details

getChunk(hash)

Retrieve a readable stream of a chunk, or null if the chunk is not present.

Parameters

NameTypeDescription
hashstringChunk identifier

Returns

Promise<Readable | null>


putChunk(hash, data, opts?)

Upload a chunk identified by its hash.

Parameters

NameTypeDescription
hashstringChunk hash
dataReadableSource data stream
opts.overwrite?booleanWhether to overwrite if exists
opts.size?numberOptional size of the chunk, often needed by some storage providers like S3

Returns

Promise<void>


chunkExists(hash)

Check if a chunk with given hash exists.

Parameters

NameTypeDescription
hashstringChunk hash

Returns

Promise<boolean>


deleteChunk(hash)

Deletes a chunk with given hash if exists.

Parameters

NameTypeDescription
hashstringChunk identifier

Returns

Promise<void>


listChunks?()

Retrieves a list of chunk hashes of the workspace. Optional method.

Returns

Promise<string[]>


getChunkInfo?(hash)

Retrieves metadata of given chunk by hash if exists. Optional method.

Parameters

NameTypeDescription
hashstringChunk identifier

Returns

Promise<BlobInfo | null>

export interface BlobInfo {
hash: string;
size: number;
modified?: Date;
metadata?: Record<string, string>;
}

getRemoteIndex()

Retrieves remote rd-index.json if found on workspace path.

Returns

Promise<RDIndex | null>


putRemoteIndex(index)

Uploads a rd-index.json to storage workspace (storage-config-path/rd-index.json).

Parameters

NameTypeDescription
indexRDIndexThe rd-index object

Returns

Promise<void>