Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
6b69edb3ef | |||
77e69171e2 | |||
365eea59bd | |||
1a64835510 | |||
b61a86f029 | |||
b9d082f07f | |||
4819dd0bc5 | |||
7250793f95 |
10826
package-lock.json
generated
10826
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
20
package.json
20
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartbucket",
|
"name": "@pushrocks/smartbucket",
|
||||||
"version": "1.0.28",
|
"version": "1.0.32",
|
||||||
"description": "simple cloud independent object storage",
|
"description": "simple cloud independent object storage",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
"typings": "dist_ts/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
@ -9,22 +9,22 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/)",
|
"test": "(tstest test/)",
|
||||||
"format": "(gitzone format)",
|
"format": "(gitzone format)",
|
||||||
"build": "(tsbuild)"
|
"build": "(tsbuild --web)"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.24",
|
"@gitzone/tsbuild": "^2.1.25",
|
||||||
"@gitzone/tstest": "^1.0.28",
|
"@gitzone/tstest": "^1.0.52",
|
||||||
"@pushrocks/tapbundle": "^3.2.1",
|
"@pushrocks/tapbundle": "^3.2.9",
|
||||||
"tslint": "^6.1.2",
|
"tslint": "^6.1.3",
|
||||||
"tslint-config-prettier": "^1.18.0"
|
"tslint-config-prettier": "^1.18.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/qenv": "^4.0.6",
|
"@pushrocks/qenv": "^4.0.10",
|
||||||
"@pushrocks/smartpath": "^4.0.3",
|
"@pushrocks/smartpath": "^4.0.3",
|
||||||
"@pushrocks/smartpromise": "^3.0.6",
|
"@pushrocks/smartpromise": "^3.0.6",
|
||||||
"@pushrocks/smartrx": "^2.0.5",
|
"@pushrocks/smartrx": "^2.0.19",
|
||||||
"@pushrocks/streamfunction": "^1.0.24",
|
"@pushrocks/streamfunction": "^2.0.1",
|
||||||
"@types/minio": "^7.0.5",
|
"@types/minio": "^7.0.6",
|
||||||
"minio": "^7.0.16"
|
"minio": "^7.0.16"
|
||||||
},
|
},
|
||||||
"private": false,
|
"private": false,
|
||||||
|
22
readme.md
22
readme.md
@ -8,16 +8,24 @@ simple cloud independent object storage
|
|||||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smartbucket/)
|
* [docs (typedoc)](https://pushrocks.gitlab.io/smartbucket/)
|
||||||
|
|
||||||
## Status for master
|
## Status for master
|
||||||
[](https://gitlab.com/pushrocks/smartbucket/commits/master)
|
|
||||||
[](https://gitlab.com/pushrocks/smartbucket/commits/master)
|
Status Category | Status Badge
|
||||||
[](https://www.npmjs.com/package/@pushrocks/smartbucket)
|
-- | --
|
||||||
[](https://snyk.io/test/npm/@pushrocks/smartbucket)
|
GitLab Pipelines | [](https://lossless.cloud)
|
||||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
npm | [](https://lossless.cloud)
|
||||||
[](https://prettier.io/)
|
Snyk | [](https://lossless.cloud)
|
||||||
|
TypeScript Support | [](https://lossless.cloud)
|
||||||
|
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
|
Code Style | [](https://lossless.cloud)
|
||||||
|
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||||
|
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||||
|
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
||||||
|
Platform support | [](https://lossless.cloud) [](https://lossless.cloud)
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
Use TypeScript for best in class intellisense.
|
||||||
|
|
||||||
## Contribution
|
## Contribution
|
||||||
|
|
||||||
|
10
test/test.ts
10
test/test.ts
@ -76,6 +76,16 @@ tap.test('should correctly build paths for sub directories', async () => {
|
|||||||
console.log(dir4BasePath);
|
console.log(dir4BasePath);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
tap.test('should list huge file directory', async () => {
|
||||||
|
const servezoneBucket = await smartbucket.Bucket.getBucketByName(testSmartbucket, 'servezone');
|
||||||
|
const servezoneBaseDirectory = await servezoneBucket.getBaseDirectory();
|
||||||
|
const brandfileDirectory = await servezoneBaseDirectory.getSubDirectoryByName('public/brandfiles');
|
||||||
|
const files = await brandfileDirectory.listFiles();
|
||||||
|
const directories = await brandfileDirectory.listDirectories();
|
||||||
|
console.log(files);
|
||||||
|
console.log(directories);
|
||||||
|
});
|
||||||
|
|
||||||
tap.test('clean up directory style tests', async () => {
|
tap.test('clean up directory style tests', async () => {
|
||||||
await myBucket.fastRemove('dir1/file1.txt');
|
await myBucket.fastRemove('dir1/file1.txt');
|
||||||
await myBucket.fastRemove('dir1/file2.txt');
|
await myBucket.fastRemove('dir1/file2.txt');
|
||||||
|
@ -65,11 +65,13 @@ export class Bucket {
|
|||||||
*/
|
*/
|
||||||
public async fastGet(pathArg: string) {
|
public async fastGet(pathArg: string) {
|
||||||
const done = plugins.smartpromise.defer();
|
const done = plugins.smartpromise.defer();
|
||||||
let completeFile: string = '';
|
let completeFile: Buffer;
|
||||||
const replaySubject = await this.fastGetStream(pathArg);
|
const replaySubject = await this.fastGetStream(pathArg);
|
||||||
replaySubject.subscribe(
|
replaySubject.subscribe(
|
||||||
chunkString => {
|
chunk => {
|
||||||
completeFile += chunkString;
|
if (completeFile) {
|
||||||
|
completeFile = Buffer.concat([completeFile, chunk]);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
err => {
|
err => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
@ -82,15 +84,14 @@ export class Bucket {
|
|||||||
return completeFile;
|
return completeFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async fastGetStream(pathArg: string): Promise<plugins.smartrx.rxjs.ReplaySubject<string>> {
|
public async fastGetStream(pathArg: string): Promise<plugins.smartrx.rxjs.ReplaySubject<Buffer>> {
|
||||||
const fileStream = await this.smartbucketRef.minioClient
|
const fileStream = await this.smartbucketRef.minioClient
|
||||||
.getObject(this.name, pathArg)
|
.getObject(this.name, pathArg)
|
||||||
.catch(e => console.log(e));
|
.catch(e => console.log(e));
|
||||||
const replaySubject = new plugins.smartrx.rxjs.ReplaySubject<string>();
|
const replaySubject = new plugins.smartrx.rxjs.ReplaySubject<Buffer>();
|
||||||
const duplexStream = plugins.streamfunction.createDuplexStream<Buffer, Buffer>(
|
const duplexStream = plugins.streamfunction.createDuplexStream<Buffer, Buffer>(
|
||||||
async chunk => {
|
async chunk => {
|
||||||
const chunkString = chunk.toString();
|
replaySubject.next(chunk);
|
||||||
replaySubject.next(chunkString);
|
|
||||||
return chunk;
|
return chunk;
|
||||||
},
|
},
|
||||||
async cb => {
|
async cb => {
|
||||||
|
@ -43,12 +43,20 @@ export class Directory {
|
|||||||
const parentDirectories = this.getParentDirectories();
|
const parentDirectories = this.getParentDirectories();
|
||||||
let basePath = '';
|
let basePath = '';
|
||||||
for (const parentDir of parentDirectories) {
|
for (const parentDir of parentDirectories) {
|
||||||
if (parentDir.name === '') {
|
if (!parentDir.name && !basePath) {
|
||||||
basePath = this.name;
|
basePath = this.name + '/';
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (parentDir.name && !basePath) {
|
||||||
|
basePath = parentDir.name + '/' + this.name + '/';
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (parentDir.name && basePath) {
|
||||||
|
basePath = parentDir.name + '/' + basePath;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
basePath = parentDir.name + '/' + this.name;
|
|
||||||
}
|
}
|
||||||
|
console.log(basePath);
|
||||||
return basePath;
|
return basePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,13 +65,17 @@ export class Directory {
|
|||||||
*/
|
*/
|
||||||
public async listFiles(): Promise<File[]> {
|
public async listFiles(): Promise<File[]> {
|
||||||
const done = plugins.smartpromise.defer();
|
const done = plugins.smartpromise.defer();
|
||||||
const fileNameStream = await this.bucketRef.smartbucketRef.minioClient.listObjects(
|
const fileNameStream = await this.bucketRef.smartbucketRef.minioClient.listObjectsV2(
|
||||||
this.bucketRef.name,
|
this.bucketRef.name,
|
||||||
this.getBasePath()
|
this.getBasePath(),
|
||||||
|
false
|
||||||
);
|
);
|
||||||
const fileArray: File[] = [];
|
const fileArray: File[] = [];
|
||||||
const duplexStream = plugins.streamfunction.createDuplexStream<plugins.minio.BucketItem, void>(
|
const duplexStream = plugins.streamfunction.createDuplexStream<plugins.minio.BucketItem, void>(
|
||||||
async bucketItem => {
|
async bucketItem => {
|
||||||
|
if (bucketItem.prefix) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!bucketItem.name) {
|
if (!bucketItem.name) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -89,15 +101,19 @@ export class Directory {
|
|||||||
*/
|
*/
|
||||||
public async listDirectories(): Promise<Directory[]> {
|
public async listDirectories(): Promise<Directory[]> {
|
||||||
const done = plugins.smartpromise.defer();
|
const done = plugins.smartpromise.defer();
|
||||||
const completeDirStream = await this.bucketRef.smartbucketRef.minioClient.listObjects(
|
const basePath = this.getBasePath();
|
||||||
|
const completeDirStream = await this.bucketRef.smartbucketRef.minioClient.listObjectsV2(
|
||||||
this.bucketRef.name,
|
this.bucketRef.name,
|
||||||
this.getBasePath(),
|
this.getBasePath(),
|
||||||
true
|
false
|
||||||
);
|
);
|
||||||
const directoryArray: Directory[] = [];
|
const directoryArray: Directory[] = [];
|
||||||
const duplexStream = plugins.streamfunction.createDuplexStream<plugins.minio.BucketItem, void>(
|
const duplexStream = plugins.streamfunction.createDuplexStream<plugins.minio.BucketItem, void>(
|
||||||
async bucketItem => {
|
async bucketItem => {
|
||||||
let subtractedPath = bucketItem.name.replace(this.getBasePath(), '');
|
if (bucketItem.name) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let subtractedPath = bucketItem.prefix.replace(this.getBasePath(), '');
|
||||||
if (subtractedPath.startsWith('/')) {
|
if (subtractedPath.startsWith('/')) {
|
||||||
subtractedPath = subtractedPath.substr(1);
|
subtractedPath = subtractedPath.substr(1);
|
||||||
}
|
}
|
||||||
@ -122,7 +138,7 @@ export class Directory {
|
|||||||
* gets an array that has all objects with a certain prefix;
|
* gets an array that has all objects with a certain prefix;
|
||||||
*/
|
*/
|
||||||
public async getTreeArray() {
|
public async getTreeArray() {
|
||||||
const treeArray = await this.bucketRef.smartbucketRef.minioClient.listObjects(
|
const treeArray = await this.bucketRef.smartbucketRef.minioClient.listObjectsV2(
|
||||||
this.bucketRef.name,
|
this.bucketRef.name,
|
||||||
this.getBasePath(),
|
this.getBasePath(),
|
||||||
true
|
true
|
||||||
@ -176,7 +192,7 @@ export class Directory {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async fastGetStream(pathArg: string): Promise<plugins.smartrx.rxjs.ReplaySubject<string>> {
|
public async fastGetStream(pathArg: string): Promise<plugins.smartrx.rxjs.ReplaySubject<Buffer>> {
|
||||||
const path = plugins.path.join(this.getBasePath(), pathArg);
|
const path = plugins.path.join(this.getBasePath(), pathArg);
|
||||||
const result = await this.bucketRef.fastGetStream(path);
|
const result = await this.bucketRef.fastGetStream(path);
|
||||||
return result;
|
return result;
|
||||||
|
Reference in New Issue
Block a user