Compare commits

..

4 Commits

Author SHA1 Message Date
27fb5f3291 1.0.12 2019-10-16 18:12:18 +02:00
34d7ef2686 fix(core): update 2019-10-16 18:12:18 +02:00
fbac742db2 1.0.11 2019-10-16 15:21:02 +02:00
3456459456 fix(core): update 2019-10-16 15:21:02 +02:00
9 changed files with 299 additions and 11 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"
}
}
}
}
]
}

30
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartbucket",
"version": "1.0.10",
"version": "1.0.12",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@ -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

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartbucket",
"version": "1.0.10",
"version": "1.0.12",
"description": "simple cloud independent object storage",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
@ -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

@ -30,8 +30,19 @@ tap.test('should get a bucket', async () => {
expect(myBucket.name).to.equal('smartbucket');
});
tap.test('should store data in bucket', async () => {
myBucket.store
// Fast operations
tap.test('should store data in bucket fast', async () => {
await myBucket.fastStore('hithere/socool.txt', 'hi there!');
});
tap.test('should get data in bucket', async () => {
const fileString = await myBucket.fastGet('hithere/socool.txt');
console.log(fileString);
});
tap.test('should delete data in bucket', async () => {
await myBucket.fastRemove('hithere/socool.txt');
});
tap.start();

View File

@ -34,10 +34,51 @@ export class Bucket {
this.name = bucketName;
}
// ===============
// Fast Operations
// ===============
/**
* store file
*/
public store(pathArg: string, fileContent: string) {
public async fastStore(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 fastGet(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 fastRemove (pathArg: string) {
await this.smartbucketRef.minioClient.removeObject(this.name, pathArg);
}
}

View File

@ -1,3 +1,69 @@
import * as plugins from './smartbucket.plugins';
import { Bucket } from './smartbucket.classes.bucket';
import { File } from './smartbucket.classes.file';
export class Directory {}
export class Directory {
public bucketRef: Bucket;
public basePath: string;
public tree: string[];
public files: string[];
public folders: string[];
constructor(bucketRefArg: Bucket, basePathArg: string) {
this.bucketRef = bucketRefArg;
this.basePath = basePathArg;
}
/**
* lists all files
*/
public async listFiles(): Promise<File[]> {
const done = plugins.smartpromise.defer();
const fileNameStream = await this.bucketRef.smartbucketRef.minioClient.listObjectsV2(
this.bucketRef.name,
this.basePath
);
const fileArray: File[] = [];
const duplexStream = plugins.streamfunction.createDuplexStream<string, void>(async fileName => {
fileArray.push(new File(this, fileName));
}, async (tools) => {
done.resolve();
});
fileNameStream.pipe(duplexStream);
await done.promise;
return fileArray;
}
/**
* lists all folders
*/
public async listDirectories() {
const done = plugins.smartpromise.defer();
const completeDirStream = await this.bucketRef.smartbucketRef.minioClient.listObjectsV2(
this.bucketRef.name,
this.basePath,
true
);
const fileArray: File[] = [];
const duplexStream = plugins.streamfunction.createDuplexStream<string, void>(async fileName => {
fileArray.push(new File(this, fileName));
}, async (tools) => {
done.resolve();
});
completeDirStream.pipe(duplexStream);
await done.promise;
return fileArray;
}
/**
* gets an array that has all objects with a certain prefix;
*/
public async getTreeArray() {
const treeArray = await this.bucketRef.smartbucketRef.minioClient.listObjectsV2(
this.bucketRef.name,
this.basePath,
true
);
}
}

View File

@ -1,3 +1,87 @@
import * as plugins from './smartbucket.plugins';
import { Directory } from './smartbucket.classes.directory';
export class File {}
export interface IFileMetaData {
name: string;
fileType: string;
size: string;
}
export class File {
// STATIC
public static async createFileFromString(
dirArg: Directory,
fileName: string,
fileContent: string
) {
await this.createFileFromBuffer(
dirArg,
fileName,
Buffer.from(fileContent)
);
}
public static async createFileFromBuffer(
directoryRef: Directory,
fileName: string,
fileContent: Buffer
) {
const filePath = plugins.path.join(directoryRef.basePath, fileName);
const streamIntake = new plugins.streamfunction.Intake();
const putPromise = directoryRef.bucketRef.smartbucketRef.minioClient
.putObject(this.name, filePath, streamIntake.getReadable())
.catch(e => console.log(e));
streamIntake.pushData(fileContent);
streamIntake.signalEnd();
await putPromise;
}
// INSTANCE
public directoryRef: Directory;
public path: string;
public metaData: IFileMetaData;
constructor(directoryRefArg: Directory, fileName: string) {
this.directoryRef = directoryRefArg;
}
public async getContentAsString() {
const fileBuffer = await this.getContentAsBuffer();
return fileBuffer.toString();
}
public async getContentAsBuffer() {
const done = plugins.smartpromise.defer();
const fileStream = await this.directoryRef.bucketRef.smartbucketRef.minioClient.getObject(this.directoryRef.bucketRef.name, this.path).catch(e => console.log(e));
let completeFile = new Buffer('');
const duplexStream = plugins.streamfunction.createDuplexStream<Buffer, Buffer>(async (chunk) => {
completeFile = Buffer.concat([chunk]);
return chunk;
}, async (cb) => {
done.resolve();
return Buffer.from('');
});
if (!fileStream) {
return null;
}
fileStream.pipe(duplexStream);
await done.promise;
return completeFile;
}
public async streamContent() {
throw new Error('not yet implemented');
// TODO
}
/**
* removes this file
*/
public async remove () {
await this.directoryRef.bucketRef.smartbucketRef.minioClient.removeObject(this.directoryRef.bucketRef.name, this.path);
await this.directoryRef.listFiles();
}
}

View File

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