smartbucket/ts/smartbucket.classes.directory.ts
2019-10-16 18:12:18 +02:00

70 lines
1.9 KiB
TypeScript

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<File[]> {
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<string, void>(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<string, void>(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
);
}
}