flydrive
Version:
File storage library with unified API to manage files across multiple cloud storage providers like S3, GCS, R2 and so on
152 lines (151 loc) • 6.31 kB
TypeScript
import { Readable } from 'node:stream';
import { S3Client, PutObjectCommand, GetObjectCommand, HeadObjectCommand, CopyObjectCommand, PutObjectAclCommand, DeleteObjectCommand, GetObjectAclCommand, ListObjectsV2Command, DeleteObjectsCommand, PutObjectCommandInput, GetObjectCommandInput, CopyObjectCommandInput, HeadObjectCommandInput, GetObjectAclCommandInput, PutObjectAclCommandInput, DeleteObjectCommandInput, ListObjectsV2CommandInput, DeleteObjectsCommandInput } from '@aws-sdk/client-s3';
import { S3DriverOptions } from './types.js';
import { DriveFile } from '../../src/driver_file.js';
import { DriveDirectory } from '../../src/drive_directory.js';
import type { WriteOptions, DriverContract, ObjectMetaData, ObjectVisibility, SignedURLOptions, UploadSignedURLOptions } from '../../src/types.js';
/**
* Implementation of FlyDrive driver that reads and persists files
* to S3 complaint storage services like Digital ocean spaces,
* R2 and so on.
*/
export declare class S3Driver implements DriverContract {
#private;
options: S3DriverOptions;
/**
* The URI that holds permission for public
*/
publicGrantUri: string;
constructor(options: S3DriverOptions);
/**
* Creates S3 "PutObjectCommand". Feel free to override this method to
* manually create the command
*/
protected createPutObjectCommand(_: S3Client, options: PutObjectCommandInput): PutObjectCommand;
/**
* Creates S3 "GetObjectCommand". Feel free to override this method to
* manually create the command
*/
protected createGetObjectCommand(_: S3Client, options: GetObjectCommandInput): GetObjectCommand;
/**
* Creates S3 "HeadObjectCommand". Feel free to override this method to
* manually create the command
*/
protected createHeadObjectCommand(_: S3Client, options: HeadObjectCommandInput): HeadObjectCommand;
/**
* Creates S3 "GetObjectAclCommand". Feel free to override this method to
* manually create the command
*/
protected createGetObjectAclCommand(_: S3Client, options: GetObjectAclCommandInput): GetObjectAclCommand;
/**
* Creates S3 "PutObjectAclCommand". Feel free to override this method to
* manually create the command
*/
protected createPutObjectAclCommand(_: S3Client, options: PutObjectAclCommandInput): PutObjectAclCommand;
/**
* Creates S3 "DeleteObjectCommand". Feel free to override this method to
* manually create the command
*/
protected createDeleteObjectCommand(_: S3Client, options: DeleteObjectCommandInput): DeleteObjectCommand;
/**
* Creates S3 "CopyObjectCommand". Feel free to override this method to
* manually create the command
*/
protected createCopyObjectCommand(_: S3Client, options: CopyObjectCommandInput): CopyObjectCommand;
/**
* Creates S3 "ListObjectsV2Command". Feel free to override this method to
* manually create the command
*/
protected createListObjectsV2Command(_: S3Client, options: ListObjectsV2CommandInput): ListObjectsV2Command;
/**
* Creates S3 "DeleteObjectsCommand". Feel free to override this method to
* manually create the command
*/
protected createDeleteObjectsCommand(_: S3Client, options: DeleteObjectsCommandInput): DeleteObjectsCommand;
/**
* 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 a signed URL for uploading objects directly to S3.
*/
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>;
}>;
}