fix(core): update

This commit is contained in:
2019-10-16 15:21:02 +02:00
parent c4374da42a
commit 3456459456
7 changed files with 130 additions and 5 deletions

View File

@@ -37,7 +37,43 @@ export class Bucket {
/**
* store file
*/
public store(pathArg: string, fileContent: string) {
public async store(pathArg: string, fileContent: string) {
const streamIntake = new plugins.streamfunction.Intake();
const putPromise = this.smartbucketRef.minioClient.putObject(this.name, pathArg, streamIntake.getReadable()).catch(e => console.log(e));
streamIntake.pushData(fileContent);
streamIntake.signalEnd();
await putPromise;
}
/**
* get file
*/
public async get(pathArg: string) {
const done = plugins.smartpromise.defer();
const fileStream = await this.smartbucketRef.minioClient.getObject(this.name, pathArg).catch(e => console.log(e));
let completeFile: string = '';
const duplexStream = plugins.streamfunction.createDuplexStream<Buffer, Buffer>(async (chunk) => {
const chunkString = chunk.toString();
completeFile += chunkString;
return chunk;
}, async (cb) => {
done.resolve();
return Buffer.from('');
});
if (!fileStream) {
return null;
}
fileStream.pipe(duplexStream);
await done.promise;
return completeFile;
}
/**
* removeObject
*/
public async remove (pathArg: string) {
await this.smartbucketRef.minioClient.removeObject(this.name, pathArg);
}
}

View File

@@ -1,6 +1,7 @@
import * as smartpromise from '@pushrocks/smartpromise';
import * as streamfunction from '@pushrocks/streamfunction';
export { smartpromise };
export { smartpromise, streamfunction };
// third party scope
import * as minio from 'minio';