@push.rocks/smartfile
Version:
Provides comprehensive tools for efficient file management in Node.js using TypeScript, including handling streams, virtual directories, and various file operations.
43 lines (42 loc) • 1.69 kB
TypeScript
import { Readable } from 'stream';
/**
* The StreamFile class represents a file as a stream.
* It allows creating streams from a file path, a URL, or a buffer.
*/
export declare class StreamFile {
static fromPath(filePath: string): Promise<StreamFile>;
static fromUrl(url: string): Promise<StreamFile>;
static fromBuffer(buffer: Buffer, relativeFilePath?: string): StreamFile;
/**
* Creates a StreamFile from an existing Readable stream with an option for multiple uses.
* @param stream A Node.js Readable stream.
* @param relativeFilePath Optional file path for the stream.
* @param multiUse If true, the stream can be read multiple times, caching its content.
* @returns A StreamFile instance.
*/
static fromStream(stream: Readable, relativeFilePath?: string, multiUse?: boolean): StreamFile;
relativeFilePath?: string;
private streamSource;
private cachedStreamBuffer?;
multiUse: boolean;
used: boolean;
byteLengthComputeFunction: () => Promise<number>;
private constructor();
private checkMultiUse;
/**
* Creates a new readable stream from the source.
*/
createReadStream(): Promise<Readable>;
/**
* Writes the stream to the disk at the specified path.
* @param filePathArg The file path where the stream should be written.
*/
writeToDisk(filePathArg: string): Promise<void>;
writeToDir(dirPathArg: string): Promise<void>;
getContentAsBuffer(): Promise<Buffer<ArrayBufferLike>>;
getContentAsString(formatArg?: 'utf8' | 'binary'): Promise<string>;
/**
* Returns the size of the file content in bytes.
*/
getSize(): Promise<number>;
}