smartbucket/ts/smartbucket.classes.directory.ts

70 lines
1.9 KiB
TypeScript
Raw Normal View History

2019-10-14 18:55:07 +00:00
import * as plugins from './smartbucket.plugins';
2019-10-16 16:12:18 +00:00
import { Bucket } from './smartbucket.classes.bucket';
import { File } from './smartbucket.classes.file';
2019-10-14 18:55:07 +00:00
2019-10-16 16:12:18 +00:00
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
);
}
}