flydrive
Version:
File storage library with unified API to manage files across multiple cloud storage providers like S3, GCS, R2 and so on
108 lines (107 loc) • 3.9 kB
TypeScript
import { type Readable } from 'node:stream';
import type { GCSDriverOptions } from './types.js';
import { DriveFile } from '../../src/driver_file.js';
import { DriveDirectory } from '../../src/drive_directory.js';
import type { WriteOptions, ObjectMetaData, DriverContract, SignedURLOptions, ObjectVisibility, UploadSignedURLOptions } from '../../src/types.js';
/**
* Implementation of FlyDrive driver that reads and persists files
* to Google cloud storage service
*/
export declare class GCSDriver implements DriverContract {
#private;
options: GCSDriverOptions;
constructor(options: GCSDriverOptions);
/**
* Returns a boolean indicating if the file exists
* or not.
*/
exists(key: string): Promise<boolean>;
/**
* Returns the contents of a file as a UTF-8 string. An
* exception is thrown when object is missing.
*/
get(key: string): Promise<string>;
/**
* Returns the contents of the file as a Readable stream. An
* exception is thrown when the file is missing.
*/
getStream(key: string): Promise<Readable>;
/**
* Returns the contents of the file as an Uint8Array. An
* exception is thrown when the file is missing.
*/
getBytes(key: string): Promise<Uint8Array>;
/**
* Returns the file metadata.
*/
getMetaData(key: string): Promise<ObjectMetaData>;
/**
* Returns the visibility of a file
*/
getVisibility(key: string): Promise<ObjectVisibility>;
/**
* Returns the public URL of the file. This method does not check
* if the file exists or not.
*/
getUrl(key: string): Promise<string>;
/**
* Returns the signed/temporary URL of the file. By default, the signed URLs
* expire in 30mins, but a custom expiry can be defined using
* "options.expiresIn" property.
*/
getSignedUrl(key: string, options?: SignedURLOptions): Promise<string>;
/**
* Returns the signed/temporary URL that can be used to directly upload
* the file contents to the storage. By default, the signed URLs
* expire in 30mins, but a custom expiry can be defined using
* "options.expiresIn" property.
*/
getSignedUploadUrl(key: string, options?: UploadSignedURLOptions): Promise<string>;
/**
* Updates the visibility of a file
*/
setVisibility(key: string, visibility: ObjectVisibility): Promise<void>;
/**
* Writes a file to the bucket for the given key and contents.
*/
put(key: string, contents: string | Uint8Array, options?: WriteOptions | undefined): Promise<void>;
/**
* Writes a file to the bucket for the given key and stream
*/
putStream(key: string, contents: Readable, options?: WriteOptions | undefined): Promise<void>;
/**
* Copies the source file to the destination. Both paths must
* be within the root location.
*/
copy(source: string, destination: string, options?: WriteOptions): Promise<void>;
/**
* Moves the source file to the destination. Both paths must
* be within the root location.
*/
move(source: string, destination: string, options?: WriteOptions): Promise<void>;
/**
* Deletes the object from the bucket
*/
delete(key: string): Promise<void>;
/**
* Deletes the files and directories matching the provided
* prefix.
*/
deleteAll(prefix: string): Promise<void>;
/**
* Returns a list of files. The pagination token can be used to paginate
* through the files.
*/
listAll(prefix: string, options?: {
recursive?: boolean;
paginationToken?: string;
maxResults?: number;
}): Promise<{
paginationToken?: string;
objects: Iterable<DriveFile | DriveDirectory>;
}>;
/**
* Switch bucket at runtime if supported.
*/
bucket(bucket: string): GCSDriver;
}