@rsksmart/rif-storage
Version:
Library integrating distributed storage projects
91 lines (90 loc) • 2.9 kB
TypeScript
/// <reference types="node" />
import { Readable } from 'stream';
import { BzzConfig, BzzMode, DownloadOptions, UploadOptions } from './types';
import { Directory, DirectoryArray } from '../definitions';
export * from './types';
export declare const BZZ_MODE_PROTOCOLS: {
default: string;
immutable: string;
raw: string;
};
export declare function getModeProtocol(mode?: BzzMode, defaultMode?: BzzMode): string;
/**
* Small simple client library for Bzz part of Swarm project.
* It communicate using HTTP API.
*/
export declare class Bzz {
private ky;
constructor(config: BzzConfig);
/**
* Fetch list of entries of given manifest hash.
*
*
* @param hash
* @param options
* @throws HTTPError when hash is not a manifest
*/
private list;
/**
* Helper method for fetching single raw file.
*
* @param hash
* @param options
*/
private getFile;
/**
* Helper method for fetching directory defined by manifest.
* It employees fetching of Tar file from Swarm with all files which is then extracted on the client side.
*
* @param hash
* @param options
*/
private getDirectory;
/**
* Method for fetching file/directory from Swarm.
*
* Buffer is returned when it is single raw hash. You can use isFile() utility function to verify if file was returned.
* Directory object is returned when it is manifest hash. You can use isDirectory() utility function to verify that it is directory.
*
* @param hash
* @param options
*/
get(hash: string, options?: DownloadOptions): Promise<Directory<Buffer> | Buffer>;
private getStream;
/**
* Helper function that fetch single raw file from Swarm returning Readable
*
* @param hash
* @param options
* @private
*/
private getRawReadable;
/**
* Helper function that fetch file(s)/directory (eq. hash is manifest) from Swarm
* returning Readable
*
* @param hash
* @param options
* @private
*/
private getManifestReadable;
/**
* Fetch data from Swarm and return Readable in object mode that yield
* objects in format {data: <Readable>, path: 'string', size: number | undefined}
* @param hash
* @param options
*/
getReadable(hash: string, options?: DownloadOptions): Promise<Readable>;
private putItToSwarm;
/**
* Add data to Swarm
*
* If to the data are given some metadata (filename), then the original data are wrapped in directory
* in order to persist these metadata.
*
* @param data
* @param options
*/
put(data: string | Buffer | Readable, options?: UploadOptions): Promise<string>;
put(data: Directory<string | Buffer | Readable> | DirectoryArray<Buffer | Readable>, options?: UploadOptions): Promise<string>;
}