UNPKG

@push.rocks/smartbucket

Version:

A TypeScript library providing a cloud-agnostic interface for managing object storage with functionalities like bucket management, file and directory operations, and advanced features such as metadata handling and file locking.

118 lines (117 loc) 3.44 kB
import * as plugins from './plugins.js'; import { Bucket } from './classes.bucket.js'; import { File } from './classes.file.js'; export declare class Directory { bucketRef: Bucket; parentDirectoryRef: Directory; name: string; tree: string[]; files: string[]; folders: string[]; constructor(bucketRefArg: Bucket, parentDirectory: Directory, name: string); /** * returns an array of parent directories */ getParentDirectories(): Directory[]; /** * returns the directory level */ getDirectoryLevel(): number; /** * updates the base path */ getBasePath(): string; /** * gets a file by name */ getFile(optionsArg: { path: string; createWithContents?: string | Buffer; getFromTrash?: boolean; }): Promise<File | null>; /** * gets a file strictly * @param args * @returns */ getFileStrict(...args: Parameters<Directory['getFile']>): Promise<File>; /** * lists all files */ listFiles(): Promise<File[]>; /** * lists all folders */ listDirectories(): Promise<Directory[]>; /** * gets an array that has all objects with a certain prefix */ getTreeArray(): Promise<plugins.s3._Object[]>; /** * gets a sub directory by name */ getSubDirectoryByName(dirNameArg: string, optionsArg?: { /** * in s3 a directory does not exist if it is empty * this option returns a directory even if it is empty */ getEmptyDirectory?: boolean; /** * in s3 a directory does not exist if it is empty * this option creates a directory even if it is empty using a initializer file */ createWithInitializerFile?: boolean; /** * if the path is a file path, it will be treated as a file and the parent directory will be returned */ couldBeFilePath?: boolean; }): Promise<Directory | null>; getSubDirectoryByNameStrict(...args: Parameters<Directory['getSubDirectoryByName']>): Promise<Directory>; /** * moves the directory */ move(): Promise<void>; /** * creates an empty file within this directory * @param relativePathArg */ createEmptyFile(relativePathArg: string): Promise<File>; fastPut(optionsArg: { path: string; contents: string | Buffer; }): Promise<void>; fastGet(optionsArg: { path: string; }): Promise<Buffer>; fastGetStream(optionsArg: { path: string; }, typeArg: 'webstream'): Promise<ReadableStream>; fastGetStream(optionsArg: { path: string; }, typeArg: 'nodestream'): Promise<plugins.stream.Readable>; /** * fast put stream */ fastPutStream(optionsArg: { path: string; stream: plugins.stream.Readable; }): Promise<void>; /** * removes a file within the directory * uses file class to make sure effects for metadata etc. are handled correctly * @param optionsArg */ fastRemove(optionsArg: { path: string; /** * wether the file should be placed into trash. Default is false. */ mode?: 'permanent' | 'trash'; }): Promise<void>; /** * deletes the directory with all its contents */ delete(optionsArg: { mode?: 'permanent' | 'trash'; }): Promise<void>; }