From 3456459456026cff1f65fc1a817ab5f155906e63 Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Wed, 16 Oct 2019 15:21:02 +0200 Subject: [PATCH] fix(core): update --- .vscode/launch.json | 29 +++++++++++++++++++++++ .vscode/settings.json | 20 ++++++++++++++++ package-lock.json | 28 ++++++++++++++++++++++ package.json | 3 ++- test/test.ts | 12 +++++++++- ts/smartbucket.classes.bucket.ts | 40 ++++++++++++++++++++++++++++++-- ts/smartbucket.plugins.ts | 3 ++- 7 files changed, 130 insertions(+), 5 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..112db52 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,29 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "current file", + "type": "node", + "request": "launch", + "args": [ + "${relativeFile}" + ], + "runtimeArgs": ["-r", "@gitzone/tsrun"], + "cwd": "${workspaceRoot}", + "protocol": "inspector", + "internalConsoleOptions": "openOnSessionStart" + }, + { + "name": "test.ts", + "type": "node", + "request": "launch", + "args": [ + "test/test.ts" + ], + "runtimeArgs": ["-r", "@gitzone/tsrun"], + "cwd": "${workspaceRoot}", + "protocol": "inspector", + "internalConsoleOptions": "openOnSessionStart" + } + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..6763058 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,20 @@ +{ + "json.schemas": [ + { + "fileMatch": ["/npmextra.json"], + "schema": { + "type": "object", + "properties": { + "npmci": { + "type": "object", + "description": "settings for npmci" + }, + "gitzone": { + "type": "object", + "description": "settings for gitzone" + } + } + } + } + ] +} diff --git a/package-lock.json b/package-lock.json index fc191e3..1d22f61 100644 --- a/package-lock.json +++ b/package-lock.json @@ -313,6 +313,17 @@ "luxon": "^1.16.0" } }, + "@pushrocks/streamfunction": { + "version": "1.0.24", + "resolved": "https://verdaccio.lossless.one/@pushrocks%2fstreamfunction/-/streamfunction-1.0.24.tgz", + "integrity": "sha512-zGxL1/i5+k+udB0kq+zP6FOXSBsSKbNeNcRratslqtOYDszIPgrMiei05Er/Lpp/hEJKCexcfu3Zi2jQnBgiXQ==", + "requires": { + "@types/from2": "^2.3.0", + "@types/through2": "^2.0.34", + "from2": "^2.3.0", + "through2": "^3.0.1" + } + }, "@pushrocks/tapbundle": { "version": "3.0.13", "resolved": "https://verdaccio.lossless.one/@pushrocks%2ftapbundle/-/tapbundle-3.0.13.tgz", @@ -381,6 +392,14 @@ "form-data": "*" } }, + "@types/from2": { + "version": "2.3.0", + "resolved": "https://verdaccio.lossless.one/@types%2ffrom2/-/from2-2.3.0.tgz", + "integrity": "sha512-WIURl4GQOp6wqa/suhVjtMh9Lgb7nnOsykAPYvwInDLbwu/hCLQcBvF57zQdEterX5sZtKQIHrSFZijvd6FDjA==", + "requires": { + "@types/node": "*" + } + }, "@types/fs-extra": { "version": "8.0.0", "resolved": "https://verdaccio.lossless.one/@types%2ffs-extra/-/fs-extra-8.0.0.tgz", @@ -864,6 +883,15 @@ "mime-types": "^2.1.12" } }, + "from2": { + "version": "2.3.0", + "resolved": "https://verdaccio.lossless.one/from2/-/from2-2.3.0.tgz", + "integrity": "sha1-i/tVAr3kpNNs/e6gB/zKIdfjgq8=", + "requires": { + "inherits": "^2.0.1", + "readable-stream": "^2.0.0" + } + }, "fs-extra": { "version": "8.1.0", "resolved": "https://verdaccio.lossless.one/fs-extra/-/fs-extra-8.1.0.tgz", diff --git a/package.json b/package.json index ab75020..9273f55 100644 --- a/package.json +++ b/package.json @@ -21,10 +21,11 @@ "dependencies": { "@pushrocks/qenv": "^4.0.6", "@pushrocks/smartpromise": "^3.0.6", + "@pushrocks/streamfunction": "^1.0.24", "@types/minio": "^7.0.3", "minio": "^7.0.12" }, - "private": true, + "private": false, "files": [ "ts/**/*", "ts_web/**/*", diff --git a/test/test.ts b/test/test.ts index 52a2377..e068b7c 100644 --- a/test/test.ts +++ b/test/test.ts @@ -31,7 +31,17 @@ tap.test('should get a bucket', async () => { }); tap.test('should store data in bucket', async () => { - myBucket.store + await myBucket.store('hithere/socool.txt', 'hi there!'); }); +tap.test('should get data in bucket', async () => { + const fileString = await myBucket.get('hithere/socool.txt'); + console.log(fileString); +}); + +tap.test('should delete data in bucket', async () => { + await myBucket.remove('hithere/socool.txt'); +}); + + tap.start(); diff --git a/ts/smartbucket.classes.bucket.ts b/ts/smartbucket.classes.bucket.ts index 282492e..c51d6fb 100644 --- a/ts/smartbucket.classes.bucket.ts +++ b/ts/smartbucket.classes.bucket.ts @@ -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(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); } } diff --git a/ts/smartbucket.plugins.ts b/ts/smartbucket.plugins.ts index bee1885..2982db9 100644 --- a/ts/smartbucket.plugins.ts +++ b/ts/smartbucket.plugins.ts @@ -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';