import * as plugins from './smartbucket.plugins'; import { Bucket } from './smartbucket.classes.bucket'; import { File } from './smartbucket.classes.file'; export class Directory { public bucketRef: Bucket; public basePath: string; public tree: string[]; public files: string[]; public folders: string[]; constructor(bucketRefArg: Bucket, basePathArg: string) { this.bucketRef = bucketRefArg; this.basePath = basePathArg; } /** * lists all files */ public async listFiles(): Promise { const done = plugins.smartpromise.defer(); const fileNameStream = await this.bucketRef.smartbucketRef.minioClient.listObjectsV2( this.bucketRef.name, this.basePath ); const fileArray: File[] = []; const duplexStream = plugins.streamfunction.createDuplexStream(async fileName => { fileArray.push(new File(this, fileName)); }, async (tools) => { done.resolve(); }); fileNameStream.pipe(duplexStream); await done.promise; return fileArray; } /** * lists all folders */ public async listDirectories() { const done = plugins.smartpromise.defer(); const completeDirStream = await this.bucketRef.smartbucketRef.minioClient.listObjectsV2( this.bucketRef.name, this.basePath, true ); const fileArray: File[] = []; const duplexStream = plugins.streamfunction.createDuplexStream(async fileName => { fileArray.push(new File(this, fileName)); }, async (tools) => { done.resolve(); }); completeDirStream.pipe(duplexStream); await done.promise; return fileArray; } /** * gets an array that has all objects with a certain prefix; */ public async getTreeArray() { const treeArray = await this.bucketRef.smartbucketRef.minioClient.listObjectsV2( this.bucketRef.name, this.basePath, true ); } }