@ludovicm67/lib-filetransfer
Version:
Library to help building a file transfer application
106 lines (105 loc) • 3.27 kB
TypeScript
import { TransferFileBlob } from "./TransferFile.js";
export type TransferFileMetadata = {
id: string;
name: string;
type: string;
size: number;
bufferLength: number;
};
export type AskFilePartCallback = (fileId: string, offset: number, limit: number) => void;
export type TransferFilePoolOptions = {
askFilePartCallback?: AskFilePartCallback;
maxBufferSize?: number;
parallelCalls?: number;
timeout?: number;
retries?: number;
};
export declare class TransferFilePool {
private transferFiles;
private maxBufferSize;
private parallelCalls;
private timeout;
private retries;
private askFilePartCallback;
constructor(options?: TransferFilePoolOptions);
/**
* Check existance of a file in the pool.
*
* @param fileId Id of the file.
* @returns true if the file exists.
*/
fileExists(fileId: string): boolean;
/**
* Store file metadata.
*
* @param metadata File metadata.
* @returns The ID of the file.
*/
storeFileMetadata(metadata: TransferFileMetadata): string;
/**
* Delete a file from the pool.
*
* @param fileId Id of the file.
*/
deleteFile(fileId: string): void;
/**
* Trigger the download of a file.
*
* @param fileId Id of the file.
* @param askFilePartCallback Callback function to ask a specific part of a file.
* @param parallelCalls Number of parallel calls to perform.
*/
downloadFile(fileId: string, askFilePartCallback?: AskFilePartCallback, parallelCalls?: number): Promise<void>;
/**
* Abort the download of a file.
*
* @param fileId Id of the file.
*/
abortFileDownload(fileId: string): void;
/**
* Add a file directly to the pool.
*
* @param blob Blob to store to the pool.
* @param name Name of the file.
* @returns The metadata of the file.
*/
addFile(blob: Blob, name: string): Promise<TransferFileMetadata>;
/**
* Read a specific part of a file.
*
* @param fileId Id of the file.
* @param offset From where to read.
* @param limit Maximum lenght of data we want to read.
* @returns ArrayBuffer containing the requested part of the file.
*/
readFilePart(fileId: string, offset: number, limit: number): ArrayBuffer;
/**
* Receive a specific part of a file.
*
* @param fileId Id of the file.
* @param offset From where it was read.
* @param limit Maximum length of read data.
* @param data ArrayBuffer containing the data of defined part of the file.
*/
receiveFilePart(fileId: string, offset: number, limit: number, data: ArrayBuffer): void;
/**
* Get informations representing a specific file.
*
* @param fileId Id of the file.
* @returns Informations representing the requested file.
*/
getFile(fileId: string): TransferFileBlob;
/**
* Get the Blob of a specific complete file.
*
* @param fileId Id of the file.
* @returns The Blob of the complete file.
*/
getBlob(fileId: string): Blob;
/**
* Remove all the data of the file.
*
* @param fileId Id of the file.
*/
clearFile(fileId: string): void;
}