UNPKG

1.48 kBPlain TextView Raw
1import { Readable, Writable } from 'stream';
2import { BucketFile, BucketType } from './types';
3
4
5
6// Note: right now use generic default with F (file) any
7export interface Driver<F = any> {
8 type: BucketType;
9 name: string;
10
11 toFile(orgFile: F): Omit<BucketFile, 'bucket'>;
12
13 /** Return the path of a cloud "file object" */
14 getPath(obj: F): string;
15
16 exists(path: string): Promise<boolean>;
17
18 /**
19 * Get and return a BucketFile for a given path (will do a cloud bucket query).
20 * Returns null if not found. Throw exception if any other exception than notfound.
21 */
22 getCloudFile(path: String): Promise<F | null>;
23
24 listCloudFiles(opts: ListCloudFilesOptions): Promise<F[]>;
25
26 downloadCloudFile(cf: F, localPath: string): Promise<void>;
27
28 uploadCloudFile(localFilePath: string, remoteFilePath: string, contentType?: string): Promise<F>;
29
30 copyCloudFile(cf: F, destDir: BucketFile): Promise<void>;
31
32 deleteCloudFile(path: string): Promise<boolean>;
33
34 downloadAsText(path: string): Promise<string>
35
36 uploadCloudContent(path: string, content: string, contentType?: string): Promise<void>;
37
38 createReadStream(path: string): Promise<Readable>;
39
40 createWriteStream(path: string): Promise<Writable>;
41
42}
43
44/** Internal Interface to the list implementation */
45export interface ListCloudFilesOptions {
46 prefix?: string; // the prefix (only)
47 glob?: string; // the eventual glob
48 delimiter?: boolean; // if true, the '/' delimiter will be set (might allow to set specific char later)
49}