From 591c99736dadc236f39159543ea6a049182c21bc Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Sun, 9 Jun 2024 16:02:33 +0200 Subject: [PATCH] fix(core): update --- ts/00_commitinfo_data.ts | 2 +- ts/classes.bucket.ts | 4 ++-- ts/classes.directory.ts | 19 +++++++++++++++++-- ts/classes.file.ts | 6 +++++- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index ef0e612..81ffe38 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@push.rocks/smartbucket', - version: '3.0.11', + version: '3.0.12', description: 'A TypeScript library offering simple and cloud-agnostic object storage with advanced features like bucket creation, file and directory management, and data streaming.' } diff --git a/ts/classes.bucket.ts b/ts/classes.bucket.ts index 3681dd8..83e6d72 100644 --- a/ts/classes.bucket.ts +++ b/ts/classes.bucket.ts @@ -216,7 +216,7 @@ export class Bucket { */ public async fastPutStream(optionsArg: { path: string; - dataStream: plugins.stream.Readable | ReadableStream; + readableStream: plugins.stream.Readable | ReadableStream; nativeMetadata?: { [key: string]: string }; overwrite?: boolean; }): Promise { @@ -233,7 +233,7 @@ export class Bucket { console.log(`Creating new object at path '${optionsArg.path}' in bucket '${this.name}'.`); } - const streamIntake = await plugins.smartstream.StreamIntake.fromStream(optionsArg.dataStream); + const streamIntake = await plugins.smartstream.StreamIntake.fromStream(optionsArg.readableStream); // Proceed with putting the object await this.smartbucketRef.minioClient.putObject( diff --git a/ts/classes.directory.ts b/ts/classes.directory.ts index 876c2b0..0ac4113 100644 --- a/ts/classes.directory.ts +++ b/ts/classes.directory.ts @@ -74,8 +74,9 @@ export class Directory { return null; } if (!exists && optionsArg.createWithContents) { - await this.fastPut({ - path: optionsArg.name, + await File.create({ + directory: this, + name: optionsArg.name, contents: optionsArg.createWithContents, }); } @@ -254,6 +255,20 @@ export class Directory { return result; } + /** + * fast put stream + */ + public async fastPutStream(optionsArg: { + path: string; + stream: plugins.stream.Readable; + }): Promise { + const path = plugins.path.join(this.getBasePath(), optionsArg.path); + await this.bucketRef.fastPutStream({ + path, + readableStream: optionsArg.stream, + }); + } + /** * removes a file within the directory * @param optionsArg diff --git a/ts/classes.file.ts b/ts/classes.file.ts index f4c2192..6ca65f4 100644 --- a/ts/classes.file.ts +++ b/ts/classes.file.ts @@ -33,6 +33,10 @@ export class File { fileName: optionsArg.name, }); if (contents instanceof plugins.stream.Readable) { + await optionsArg.directory.fastPutStream({ + path: optionsArg.name, + stream: contents, + }); } else { await optionsArg.directory.fastPut({ path: optionsArg.name, @@ -160,7 +164,7 @@ export class File { ) { await this.parentDirectoryRef.bucketRef.fastPutStream({ path: this.getBasePath(), - dataStream: optionsArg.contents, + readableStream: optionsArg.contents, }); } else if (Buffer.isBuffer(optionsArg.contents)) { await this.parentDirectoryRef.bucketRef.fastPut({