fix(core): update
This commit is contained in:
		| @@ -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; | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|   | ||||
| @@ -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); | ||||
|   | ||||
| @@ -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'; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user