Compare commits

..

4 Commits

Author SHA1 Message Date
9629a04da6 3.0.13 2024-06-09 16:32:33 +02:00
963463d40d fix(core): update 2024-06-09 16:32:32 +02:00
ce58b99fc7 3.0.12 2024-06-09 16:02:34 +02:00
591c99736d fix(core): update 2024-06-09 16:02:33 +02:00
6 changed files with 29 additions and 15 deletions

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "@push.rocks/smartbucket", "name": "@push.rocks/smartbucket",
"version": "3.0.11", "version": "3.0.13",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "@push.rocks/smartbucket", "name": "@push.rocks/smartbucket",
"version": "3.0.11", "version": "3.0.13",
"license": "UNLICENSED", "license": "UNLICENSED",
"dependencies": { "dependencies": {
"@push.rocks/smartpath": "^5.0.18", "@push.rocks/smartpath": "^5.0.18",

View File

@ -1,6 +1,6 @@
{ {
"name": "@push.rocks/smartbucket", "name": "@push.rocks/smartbucket",
"version": "3.0.11", "version": "3.0.13",
"description": "A TypeScript library offering simple and cloud-agnostic object storage with advanced features like bucket creation, file and directory management, and data streaming.", "description": "A TypeScript library offering simple and cloud-agnostic object storage with advanced features like bucket creation, file and directory management, and data streaming.",
"main": "dist_ts/index.js", "main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts", "typings": "dist_ts/index.d.ts",

View File

@ -3,6 +3,6 @@
*/ */
export const commitinfo = { export const commitinfo = {
name: '@push.rocks/smartbucket', name: '@push.rocks/smartbucket',
version: '3.0.11', version: '3.0.13',
description: 'A TypeScript library offering simple and cloud-agnostic object storage with advanced features like bucket creation, file and directory management, and data streaming.' description: 'A TypeScript library offering simple and cloud-agnostic object storage with advanced features like bucket creation, file and directory management, and data streaming.'
} }

View File

@ -216,7 +216,7 @@ export class Bucket {
*/ */
public async fastPutStream(optionsArg: { public async fastPutStream(optionsArg: {
path: string; path: string;
dataStream: plugins.stream.Readable | ReadableStream; readableStream: plugins.stream.Readable | ReadableStream;
nativeMetadata?: { [key: string]: string }; nativeMetadata?: { [key: string]: string };
overwrite?: boolean; overwrite?: boolean;
}): Promise<void> { }): Promise<void> {
@ -233,7 +233,7 @@ export class Bucket {
console.log(`Creating new object at path '${optionsArg.path}' in bucket '${this.name}'.`); console.log(`Creating new object at path '${optionsArg.path}' in bucket '${this.name}'.`);
} }
const streamIntake = await plugins.smartstream.StreamIntake.fromStream<Uint8Array>(optionsArg.dataStream); const streamIntake = await plugins.smartstream.StreamIntake.fromStream<Uint8Array>(optionsArg.readableStream);
// Proceed with putting the object // Proceed with putting the object
await this.smartbucketRef.minioClient.putObject( await this.smartbucketRef.minioClient.putObject(
@ -241,12 +241,7 @@ export class Bucket {
optionsArg.path, optionsArg.path,
streamIntake, streamIntake,
null, null,
...(optionsArg.nativeMetadata null, // TODO: Add support for custom metadata once proper support is in minio.
? (() => {
const returnObject: any = {};
return returnObject;
})()
: {})
); );
console.log(`Object '${optionsArg.path}' has been successfully stored in bucket '${this.name}'.`); console.log(`Object '${optionsArg.path}' has been successfully stored in bucket '${this.name}'.`);

View File

@ -74,8 +74,9 @@ export class Directory {
return null; return null;
} }
if (!exists && optionsArg.createWithContents) { if (!exists && optionsArg.createWithContents) {
await this.fastPut({ await File.create({
path: optionsArg.name, directory: this,
name: optionsArg.name,
contents: optionsArg.createWithContents, contents: optionsArg.createWithContents,
}); });
} }
@ -254,6 +255,20 @@ export class Directory {
return result; return result;
} }
/**
* fast put stream
*/
public async fastPutStream(optionsArg: {
path: string;
stream: plugins.stream.Readable;
}): Promise<void> {
const path = plugins.path.join(this.getBasePath(), optionsArg.path);
await this.bucketRef.fastPutStream({
path,
readableStream: optionsArg.stream,
});
}
/** /**
* removes a file within the directory * removes a file within the directory
* @param optionsArg * @param optionsArg

View File

@ -33,6 +33,10 @@ export class File {
fileName: optionsArg.name, fileName: optionsArg.name,
}); });
if (contents instanceof plugins.stream.Readable) { if (contents instanceof plugins.stream.Readable) {
await optionsArg.directory.fastPutStream({
path: optionsArg.name,
stream: contents,
});
} else { } else {
await optionsArg.directory.fastPut({ await optionsArg.directory.fastPut({
path: optionsArg.name, path: optionsArg.name,
@ -160,7 +164,7 @@ export class File {
) { ) {
await this.parentDirectoryRef.bucketRef.fastPutStream({ await this.parentDirectoryRef.bucketRef.fastPutStream({
path: this.getBasePath(), path: this.getBasePath(),
dataStream: optionsArg.contents, readableStream: optionsArg.contents,
}); });
} else if (Buffer.isBuffer(optionsArg.contents)) { } else if (Buffer.isBuffer(optionsArg.contents)) {
await this.parentDirectoryRef.bucketRef.fastPut({ await this.parentDirectoryRef.bucketRef.fastPut({