prime-sdk 2.1.2 → 2.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/external/aws/s3/s3.service.js +4 -0
- package/dist/external/aws/s3/s3.service.js.map +1 -1
- package/dist/lib/storage/storage.d.ts +3 -0
- package/dist/lib/storage/storage.js +15 -0
- package/dist/lib/storage/storage.js.map +1 -1
- package/dist/lib/storage/types/storage.type.d.ts +2 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/external/aws/s3/s3.service.ts +4 -0
- package/src/lib/storage/storage.ts +21 -0
- package/src/lib/storage/types/storage.type.ts +2 -0
package/package.json
CHANGED
|
@@ -34,6 +34,10 @@ export class S3 implements IStorage {
|
|
|
34
34
|
Bucket: file.bucket,
|
|
35
35
|
Key: `${file.path}/${file.nameFile}`,
|
|
36
36
|
Body: file.file,
|
|
37
|
+
...(file.metadata && { Metadata: file.metadata }),
|
|
38
|
+
...(file.tagging && {
|
|
39
|
+
Tagging: file.tagging,
|
|
40
|
+
}),
|
|
37
41
|
});
|
|
38
42
|
|
|
39
43
|
const response = await this.client.send(command);
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
ListFiles,
|
|
17
17
|
UploadFile,
|
|
18
18
|
} from './types/storage.type';
|
|
19
|
+
import { Readable } from 'stream';
|
|
19
20
|
|
|
20
21
|
@Injectable()
|
|
21
22
|
export class Storage {
|
|
@@ -48,4 +49,24 @@ export class Storage {
|
|
|
48
49
|
async copyFile(data: CopyFile): Promise<CopyObjectCommandOutput> {
|
|
49
50
|
return this.storage.copyFile(data);
|
|
50
51
|
}
|
|
52
|
+
|
|
53
|
+
async getFileBuffer(file: GetFile): Promise<Buffer> {
|
|
54
|
+
const response = await this.storage.getFile(file);
|
|
55
|
+
|
|
56
|
+
if (!response.Body) {
|
|
57
|
+
throw new Error('s3_file_empty');
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return this.streamToBuffer(response.Body as Readable);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
private async streamToBuffer(stream: Readable): Promise<Buffer> {
|
|
64
|
+
const chunks = [];
|
|
65
|
+
|
|
66
|
+
return new Promise((resolve, reject) => {
|
|
67
|
+
stream.on('data', (chunk) => chunks.push(chunk));
|
|
68
|
+
stream.on('end', () => resolve(Buffer.concat(chunks)));
|
|
69
|
+
stream.on('error', reject);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
51
72
|
}
|