fix(core): update
This commit is contained in:
		| @@ -3,6 +3,6 @@ | ||||
|  */ | ||||
| export const commitinfo = { | ||||
|   name: '@push.rocks/smartbucket', | ||||
|   version: '2.0.4', | ||||
|   description: 'simple cloud independent object storage' | ||||
|   version: '2.0.5', | ||||
|   description: 'A TypeScript library for simple cloud independent object storage with support for buckets, directories, and files.' | ||||
| } | ||||
|   | ||||
| @@ -49,7 +49,7 @@ export class Bucket { | ||||
|   /** | ||||
|    * store file | ||||
|    */ | ||||
|   public async fastStore(pathArg: string, fileContent: string | Buffer): Promise<void> { | ||||
|   public async fastPut(pathArg: string, fileContent: string | Buffer): Promise<void> { | ||||
|     const streamIntake = new plugins.smartstream.StreamIntake(); | ||||
|     const putPromise = this.smartbucketRef.minioClient | ||||
|       .putObject(this.name, pathArg, streamIntake.getReadable()) | ||||
| @@ -115,6 +115,59 @@ export class Bucket { | ||||
|     return replaySubject; | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * store file as stream | ||||
|    */ | ||||
|   public async fastPutStream(optionsArg: { | ||||
|     pathArg: string; | ||||
|     dataStream: plugins.stream.Readable; | ||||
|     metadata?: { [key: string]: string }; | ||||
|   }): Promise<void> { | ||||
|     await this.smartbucketRef.minioClient.putObject( | ||||
|       this.name, | ||||
|       optionsArg.pathArg, | ||||
|       optionsArg.dataStream, | ||||
|       null, | ||||
|       ...(optionsArg.metadata | ||||
|         ? (() => { | ||||
|             const returnObject: any = {}; | ||||
|             return returnObject; | ||||
|           })() | ||||
|         : {}) | ||||
|     ); | ||||
|   } | ||||
|  | ||||
|   public async updateMetadata( | ||||
|     bucket: string, | ||||
|     objectKey: string, | ||||
|     metadata: { [key: string]: string } | ||||
|   ): Promise<void> { | ||||
|     try { | ||||
|       // Retrieve current object information to use in copy conditions | ||||
|       const currentObjInfo = await this.smartbucketRef.minioClient.statObject(bucket, objectKey); | ||||
|    | ||||
|       // Setting up copy conditions | ||||
|       const copyConditions = new plugins.minio.CopyConditions(); | ||||
|    | ||||
|       // Prepare new metadata, merging current and new metadata | ||||
|       const newMetadata = { | ||||
|         ...currentObjInfo.metaData, | ||||
|         ...metadata, | ||||
|       }; | ||||
|    | ||||
|       // Define the copy operation as a Promise | ||||
|       await this.smartbucketRef.minioClient.copyObject( | ||||
|         bucket, | ||||
|         objectKey, | ||||
|         `/${bucket}/${objectKey}`, | ||||
|         copyConditions, | ||||
|       ); | ||||
|     } catch (err) { | ||||
|       console.error('Error updating metadata:', err); | ||||
|       throw err; // rethrow to allow caller to handle | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * removeObject | ||||
|    */ | ||||
|   | ||||
| @@ -183,7 +183,7 @@ export class Directory { | ||||
|   // file operations | ||||
|   public async fastStore(pathArg: string, contentArg: string | Buffer) { | ||||
|     const path = plugins.path.join(this.getBasePath(), pathArg); | ||||
|     await this.bucketRef.fastStore(path, contentArg); | ||||
|     await this.bucketRef.fastPut(path, contentArg); | ||||
|   } | ||||
|  | ||||
|   public async fastGet(pathArg: string) { | ||||
|   | ||||
| @@ -1,7 +1,8 @@ | ||||
| // node native | ||||
| import * as path from 'path'; | ||||
| import * as stream from 'stream'; | ||||
|  | ||||
| export { path }; | ||||
| export { path, stream }; | ||||
|  | ||||
| // @push.rocks scope | ||||
| import * as smartpath from '@push.rocks/smartpath'; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user