Compare commits

..

10 Commits

Author SHA1 Message Date
9ad70a9942 1.0.21 2019-10-20 00:45:12 +02:00
bc41089925 fix(core): update 2019-10-20 00:45:11 +02:00
ab39809c2a 1.0.20 2019-10-19 22:57:37 +02:00
cede6c7539 fix(core): update 2019-10-19 22:57:36 +02:00
547692ac62 1.0.19 2019-10-18 18:44:55 +02:00
5410df0011 fix(core): update 2019-10-18 18:44:54 +02:00
5b8a55d6d2 1.0.18 2019-10-18 18:37:43 +02:00
61145d5e80 fix(core): update 2019-10-18 18:37:43 +02:00
6596893ee5 1.0.17 2019-10-18 15:43:06 +02:00
514a8407f6 fix(core): update 2019-10-18 15:43:06 +02:00
5 changed files with 64 additions and 25 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartbucket",
"version": "1.0.16",
"version": "1.0.21",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartbucket",
"version": "1.0.16",
"version": "1.0.21",
"description": "simple cloud independent object storage",
"main": "dist/index.js",
"typings": "dist/index.d.ts",

View File

@ -58,9 +58,20 @@ tap.test('prepare for directory style tests', async () => {
tap.test('should get base directory', async () => {
baseDirectory = await myBucket.getBaseDirectory();
const directories = await baseDirectory.listDirectories();
console.log('Found the following directories:');
console.log(directories);
expect(directories.length).to.equal(3);
const files = await baseDirectory.listFiles();
console.log('Found the following files:');
console.log(files);
expect(files.length).to.equal(1);
});
tap.test('should correctly build paths for sub directories', async () => {
const dir1 = await baseDirectory.getSubDirectoryByName('dir1');
expect(dir1).to.be.instanceOf(smartbucket.Directory);
const dir1BasePath = dir1.getBasePath();
console.log(dir1BasePath);
});
tap.test('clean up directory style tests', async () => {

View File

@ -4,7 +4,7 @@ import { File } from './smartbucket.classes.file';
export class Directory {
public bucketRef: Bucket;
public parentDirectory: Directory;
public parentDirectoryRef: Directory;
public name: string;
public tree: string[];
@ -13,7 +13,7 @@ export class Directory {
constructor(bucketRefArg: Bucket, parentDiretory: Directory, name: string) {
this.bucketRef = bucketRefArg;
this.parentDirectory = parentDiretory;
this.parentDirectoryRef = parentDiretory;
this.name = name;
}
@ -22,9 +22,9 @@ export class Directory {
*/
public getParentDirectories(): Directory[] {
let parentDirectories: Directory[] = [];
if (this.parentDirectory) {
parentDirectories.push(this.parentDirectory);
parentDirectories = parentDirectories.concat(this.parentDirectory.getParentDirectories());
if (this.parentDirectoryRef) {
parentDirectories.push(this.parentDirectoryRef);
parentDirectories = parentDirectories.concat(this.parentDirectoryRef.getParentDirectories());
}
return parentDirectories;
}
@ -43,7 +43,7 @@ export class Directory {
const parentDirectories = this.getParentDirectories();
let basePath = '';
for (const parentDir of parentDirectories) {
basePath = parentDir.name + '/' + basePath;
basePath = parentDir.name + '/' + this.name;
}
return basePath;
}
@ -58,9 +58,16 @@ export class Directory {
this.getBasePath()
);
const fileArray: File[] = [];
const duplexStream = plugins.streamfunction.createDuplexStream<string, void>(
async fileName => {
fileArray.push(new File(this, fileName));
const duplexStream = plugins.streamfunction.createDuplexStream<plugins.minio.BucketItem, void>(
async bucketItem => {
if(!bucketItem.name) {
return;
}
const subtractedPath = bucketItem.name.replace(this.getBasePath(), '');
if (!subtractedPath.includes('/')) {
fileArray.push(new File(this, bucketItem.name));
}
},
async tools => {
done.resolve();
@ -83,11 +90,10 @@ export class Directory {
);
const directoryArray: Directory[] = [];
const duplexStream = plugins.streamfunction.createDuplexStream<plugins.minio.BucketItem, void>(
async fileName => {
console.log(fileName);
const subtractedPath = fileName.name.replace(this.getBasePath(), '');
async bucketItem => {
const subtractedPath = bucketItem.name.replace(this.getBasePath(), '');
if (subtractedPath.includes('/')) {
const dirName = fileName.name.split('/')[0];
const dirName = bucketItem.name.split('/')[0];
if (directoryArray.find(directory => directory.name === dirName)) {
return;
}
@ -117,9 +123,12 @@ export class Directory {
/**
* gets a sub directory
*/
public async getSubDirectory(): Promise<Directory> {
return this;
// TODO
public async getSubDirectoryByName(dirNameArg: string): Promise<Directory> {
// TODO: make this recursive
const directories = await this.listDirectories();
return directories.find(directory => {
return directory.name === dirNameArg;
});
}
/**
@ -136,4 +145,21 @@ export class Directory {
public async createFile(relativePathArg) {
let completeFilePath: string = '';
}
// file operations
public async fastStore(pathArg: string, contentArg: string) {
const path = plugins.path.join(this.getBasePath(), pathArg);
await this.bucketRef.fastStore(path, contentArg);
}
public async fastGet(pathArg: string) {
const path = plugins.path.join(this.getBasePath(), pathArg);
const result = await this.bucketRef.fastGet(path);
return result;
}
public async fastRemove(pathArg: string) {
const path = plugins.path.join(this.getBasePath(), pathArg);
await this.bucketRef.fastRemove(path);
}
}

View File

@ -33,13 +33,15 @@ export class File {
}
// INSTANCE
public directoryRef: Directory;
public parentDirectoryRef: Directory;
public name: string;
public path: string;
public metaData: IFileMetaData;
constructor(directoryRefArg: Directory, fileName: string) {
this.directoryRef = directoryRefArg;
this.parentDirectoryRef = directoryRefArg;
this.name = fileName;
}
public async getContentAsString() {
@ -49,8 +51,8 @@ export class File {
public async getContentAsBuffer() {
const done = plugins.smartpromise.defer();
const fileStream = await this.directoryRef.bucketRef.smartbucketRef.minioClient
.getObject(this.directoryRef.bucketRef.name, this.path)
const fileStream = await this.parentDirectoryRef.bucketRef.smartbucketRef.minioClient
.getObject(this.parentDirectoryRef.bucketRef.name, this.path)
.catch(e => console.log(e));
let completeFile = new Buffer('');
const duplexStream = plugins.streamfunction.createDuplexStream<Buffer, Buffer>(
@ -82,10 +84,10 @@ export class File {
* removes this file
*/
public async remove() {
await this.directoryRef.bucketRef.smartbucketRef.minioClient.removeObject(
this.directoryRef.bucketRef.name,
await this.parentDirectoryRef.bucketRef.smartbucketRef.minioClient.removeObject(
this.parentDirectoryRef.bucketRef.name,
this.path
);
await this.directoryRef.listFiles();
await this.parentDirectoryRef.listFiles();
}
}