idea-aws 4.5.1 → 4.5.2
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/src/s3.d.ts +17 -0
- package/dist/src/s3.js +25 -1
- package/package.json +1 -1
package/dist/src/s3.d.ts
CHANGED
|
@@ -40,6 +40,7 @@ export declare class S3 {
|
|
|
40
40
|
getObjectAsJSON(options: GetObjectOptions): Promise<any>;
|
|
41
41
|
/**
|
|
42
42
|
* Get an object from a S3 bucket and convert the content to string.
|
|
43
|
+
* If the object was stored with `Content-Encoding: gzip`, it is decompressed transparently.
|
|
43
44
|
*/
|
|
44
45
|
getObjectAsText(options: GetObjectOptions): Promise<string>;
|
|
45
46
|
/**
|
|
@@ -83,6 +84,17 @@ export interface CreateDownloadURLFromDataOptions {
|
|
|
83
84
|
* Content type, e.g. application/json; default: _guessed_.
|
|
84
85
|
*/
|
|
85
86
|
contentType?: string;
|
|
87
|
+
/**
|
|
88
|
+
* If true, the body is gzipped with `Content-Encoding: gzip`. Browsers and `fetch` decompress transparently.
|
|
89
|
+
* Recommended for text/JSON payloads over ~50 KB; for already-compressed binaries (images, zip, etc.) leave it off.
|
|
90
|
+
* Only applied when `data` is a `string`, `Buffer`, or `Uint8Array`; silently ignored for other body types.
|
|
91
|
+
*/
|
|
92
|
+
compress?: boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Explicit `Content-Encoding` to store on the object (e.g., `'gzip'`, `'br'`).
|
|
95
|
+
* Use this when the body is already compressed. Ignored when `compress: true` (in that case `'gzip'` is forced).
|
|
96
|
+
*/
|
|
97
|
+
contentEncoding?: string;
|
|
86
98
|
/**
|
|
87
99
|
* Seconds to URL expiration; default: `180`.
|
|
88
100
|
*/
|
|
@@ -179,6 +191,11 @@ export interface PutObjectOptions {
|
|
|
179
191
|
* Content type (e.g. image/png).
|
|
180
192
|
*/
|
|
181
193
|
contentType?: string;
|
|
194
|
+
/**
|
|
195
|
+
* `Content-Encoding` header to store on the object (e.g., `'gzip'`).
|
|
196
|
+
* The body is uploaded as-is; the caller is responsible for pre-compressing it.
|
|
197
|
+
*/
|
|
198
|
+
contentEncoding?: string;
|
|
182
199
|
/**
|
|
183
200
|
* Access-control list (e.g. public-read).
|
|
184
201
|
*/
|
package/dist/src/s3.js
CHANGED
|
@@ -34,6 +34,8 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.cleanFilename = exports.S3 = void 0;
|
|
37
|
+
const node_zlib_1 = require("node:zlib");
|
|
38
|
+
const node_util_1 = require("node:util");
|
|
37
39
|
const AWSS3 = __importStar(require("@aws-sdk/client-s3"));
|
|
38
40
|
const lib_storage_1 = require("@aws-sdk/lib-storage");
|
|
39
41
|
const s3_request_presigner_1 = require("@aws-sdk/s3-request-presigner");
|
|
@@ -62,7 +64,21 @@ class S3 {
|
|
|
62
64
|
options.key = `${options.prefix ?? this.DEFAULT_DOWNLOAD_BUCKET_PREFIX}/${options.key}`;
|
|
63
65
|
options.bucket = options.bucket ?? this.DEFAULT_DOWNLOAD_BUCKET;
|
|
64
66
|
options.secToExp = options.secToExp ?? this.DEFAULT_DOWNLOAD_BUCKET_SEC_TO_EXP;
|
|
65
|
-
|
|
67
|
+
let body = data;
|
|
68
|
+
let contentEncoding = options.contentEncoding;
|
|
69
|
+
if (options.compress && (typeof data === 'string' || data instanceof Uint8Array)) {
|
|
70
|
+
const gzip = (0, node_util_1.promisify)(node_zlib_1.gzip);
|
|
71
|
+
body = await gzip(data);
|
|
72
|
+
contentEncoding = 'gzip';
|
|
73
|
+
}
|
|
74
|
+
const params = {
|
|
75
|
+
Bucket: options.bucket,
|
|
76
|
+
Key: options.key,
|
|
77
|
+
Body: body,
|
|
78
|
+
ContentType: options.contentType
|
|
79
|
+
};
|
|
80
|
+
if (contentEncoding)
|
|
81
|
+
params.ContentEncoding = contentEncoding;
|
|
66
82
|
const upload = new lib_storage_1.Upload({ client: this.client, params });
|
|
67
83
|
await upload.done();
|
|
68
84
|
return this.signedURLGet(options.bucket, options.key, { secToExp: options.secToExp, filename: options.filename });
|
|
@@ -121,9 +137,15 @@ class S3 {
|
|
|
121
137
|
}
|
|
122
138
|
/**
|
|
123
139
|
* Get an object from a S3 bucket and convert the content to string.
|
|
140
|
+
* If the object was stored with `Content-Encoding: gzip`, it is decompressed transparently.
|
|
124
141
|
*/
|
|
125
142
|
async getObjectAsText(options) {
|
|
126
143
|
const result = await this.getObject(options);
|
|
144
|
+
if (result.ContentEncoding === 'gzip') {
|
|
145
|
+
const gunzip = (0, node_util_1.promisify)(node_zlib_1.gunzip);
|
|
146
|
+
const compressed = await result.Body.transformToByteArray();
|
|
147
|
+
return (await gunzip(Buffer.from(compressed))).toString('utf-8');
|
|
148
|
+
}
|
|
127
149
|
return await result.Body.transformToString('utf-8');
|
|
128
150
|
}
|
|
129
151
|
/**
|
|
@@ -133,6 +155,8 @@ class S3 {
|
|
|
133
155
|
const params = { Bucket: options.bucket, Key: options.key, Body: options.body };
|
|
134
156
|
if (options.contentType)
|
|
135
157
|
params.ContentType = options.contentType;
|
|
158
|
+
if (options.contentEncoding)
|
|
159
|
+
params.ContentEncoding = options.contentEncoding;
|
|
136
160
|
if (options.acl)
|
|
137
161
|
params.ACL = options.acl;
|
|
138
162
|
if (options.metadata)
|