UNPKG

flydrive

Version:

File storage library with unified API to manage files across multiple cloud storage providers like S3, GCS, R2 and so on

75 lines (74 loc) 2.3 kB
import { type Readable } from 'node:stream'; import type { DriverContract, FileSnapshot, ObjectMetaData, ObjectVisibility, SignedURLOptions } from './types.js'; /** * DriveFile is a pointer to a given object. It can be used to lazily * read the file contents and metadata and also you may convert it * to a snapshot and persist it inside the database. */ export declare class DriveFile { #private; /** * Reference to the normalized file key */ key: string; /** * The basename of the file. Extracted from the key */ name: string; /** * Flags to know if the object is a file or a directory */ isFile: true; isDirectory: false; constructor(key: string, driver: DriverContract, metaData?: ObjectMetaData); /** * Check if the file exists. This method cannot check existence * of directories. */ exists(): Promise<boolean>; /** * Returns file contents as a UTF-8 string. Use "getArrayBuffer" method * if you need more control over the file contents decoding. */ get(): Promise<string>; /** * Returns file contents as a Readable stream. */ getStream(): Promise<Readable>; /** * Returns file contents as a Uint8Array. */ getBytes(): Promise<Uint8Array>; /** * @deprecated * @see {@link DriveFile.getBytes} */ getArrayBuffer(): Promise<Uint8Array>; /** * Returns metadata of the given file. */ getMetaData(): Promise<ObjectMetaData>; /** * Returns the visibility of the file */ getVisibility(): Promise<ObjectVisibility>; /** * Returns the public URL of the file */ getUrl(): Promise<string>; /** * Returns a signed/temporary URL of the file */ getSignedUrl(options?: SignedURLOptions): Promise<string>; /** * Returns a signed/temporary URL that can be used to directly upload * the file contents to the storage. */ getSignedUploadUrl(options?: SignedURLOptions): Promise<string>; /** * Returns a snapshot of the file. The snapshot could be persisted * within any database storage and later you can create a file * instance from it using the "disk.fromSnapshot" method. */ toSnapshot(): Promise<FileSnapshot>; }