fix(core): update

This commit is contained in:
Philipp Kunz 2024-05-05 19:52:50 +02:00
parent caa69ae6ba
commit b871e23052
5 changed files with 66 additions and 12 deletions

View File

@ -33,7 +33,7 @@ tap.test('should get a bucket', async () => {
// Fast operations
tap.test('should store data in bucket fast', async () => {
await myBucket.fastStore('hithere/socool.txt', 'hi there!');
await myBucket.fastPut('hithere/socool.txt', 'hi there!');
});
tap.test('should get data in bucket', async () => {
@ -49,12 +49,12 @@ tap.test('should delete data in bucket', async () => {
// fs operations
tap.test('prepare for directory style tests', async () => {
await myBucket.fastStore('dir1/file1.txt', 'dir1/file1.txt content');
await myBucket.fastStore('dir1/file2.txt', 'dir1/file2.txt content');
await myBucket.fastStore('dir2/file1.txt', 'dir2/file1.txt content');
await myBucket.fastStore('dir3/file1.txt', 'dir3/file1.txt content');
await myBucket.fastStore('dir3/dir4/file1.txt', 'dir3/dir4/file1.txt content');
await myBucket.fastStore('file1.txt', 'file1 content');
await myBucket.fastPut('dir1/file1.txt', 'dir1/file1.txt content');
await myBucket.fastPut('dir1/file2.txt', 'dir1/file2.txt content');
await myBucket.fastPut('dir2/file1.txt', 'dir2/file1.txt content');
await myBucket.fastPut('dir3/file1.txt', 'dir3/file1.txt content');
await myBucket.fastPut('dir3/dir4/file1.txt', 'dir3/dir4/file1.txt content');
await myBucket.fastPut('file1.txt', 'file1 content');
});
tap.test('should get base directory', async () => {

View File

@ -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.'
}

View File

@ -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
*/

View File

@ -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) {

View File

@ -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';