fix(core): update

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

29
.vscode/launch.json vendored Normal file
View File

@ -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"
}
]
}

20
.vscode/settings.json vendored Normal file
View File

@ -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"
}
}
}
}
]
}

28
package-lock.json generated
View File

@ -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",

View File

@ -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/**/*",

View File

@ -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();

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';