fix(core): update

This commit is contained in:
2019-10-20 12:27:58 +02:00
parent 1089c8f3ec
commit 51c6b29b58
5 changed files with 41 additions and 31 deletions

View File

@ -1,6 +1,7 @@
import * as plugins from './smartbucket.plugins';
import { SmartBucket } from './smartbucket.classes.smartbucket';
import { Directory } from './smartbucket.classes.directory';
import { Observable } from 'rxjs';
export class Bucket {
public static async getBucketByName(smartbucketRef: SmartBucket, bucketNameArg: string) {
@ -64,18 +65,36 @@ export class Bucket {
*/
public async fastGet(pathArg: string) {
const done = plugins.smartpromise.defer();
let completeFile: string = '';
const replaySubject = await this.fastGetStream(pathArg);
replaySubject.subscribe(
chunkString => {
completeFile += chunkString;
},
err => {
console.log(err);
},
() => {
done.resolve();
}
);
await done.promise;
return completeFile;
}
public async fastGetStream(pathArg: string): Promise<plugins.smartrx.rxjs.ReplaySubject<string>> {
const fileStream = await this.smartbucketRef.minioClient
.getObject(this.name, pathArg)
.catch(e => console.log(e));
let completeFile: string = '';
const replaySubject = new plugins.smartrx.rxjs.ReplaySubject<string>();
const duplexStream = plugins.streamfunction.createDuplexStream<Buffer, Buffer>(
async chunk => {
const chunkString = chunk.toString();
completeFile += chunkString;
replaySubject.next(chunkString);
return chunk;
},
async cb => {
done.resolve();
replaySubject.complete();
return Buffer.from('');
}
);
@ -85,8 +104,7 @@ export class Bucket {
}
fileStream.pipe(duplexStream);
await done.promise;
return completeFile;
return replaySubject;
}
/**

View File

@ -177,6 +177,12 @@ export class Directory {
return result;
}
public async fastGetStream(pathArg: string): Promise<plugins.smartrx.rxjs.ReplaySubject<string>> {
const path = plugins.path.join(this.getBasePath(), pathArg);
const result = await this.bucketRef.fastGetStream(path);
return result;
}
public async fastRemove(pathArg: string) {
const path = plugins.path.join(this.getBasePath(), pathArg);
await this.bucketRef.fastRemove(path);

View File

@ -5,9 +5,10 @@ export { path };
import * as smartpath from '@pushrocks/smartpath';
import * as smartpromise from '@pushrocks/smartpromise';
import * as smartrx from '@pushrocks/smartrx';
import * as streamfunction from '@pushrocks/streamfunction';
export { smartpath, smartpromise, streamfunction };
export { smartpath, smartpromise, smartrx, streamfunction };
// third party scope
import * as minio from 'minio';