@quatrain/storage-s3 1.2.9-beta.0 → 1.2.10-beta.0
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.
|
@@ -88,11 +88,13 @@ export declare class S3StorageAdapter extends AbstractStorageAdapter {
|
|
|
88
88
|
*/
|
|
89
89
|
getMetaData(file: FileType): Promise<FileType>;
|
|
90
90
|
/**
|
|
91
|
-
*
|
|
91
|
+
* Fetches and streams an S3 object into an external HTTP response or writable stream.
|
|
92
|
+
* Piped directly if `res` is a Writable stream (implements `.on()`), or dispatches via `.send()` / `.write()`
|
|
93
|
+
* as a defensive fallback for non-stream response objects.
|
|
92
94
|
*
|
|
93
|
-
* @param file - Target file.
|
|
94
|
-
* @param res - The response or writable stream.
|
|
95
|
-
* @returns The piped stream instance.
|
|
95
|
+
* @param file - Target file footprint.
|
|
96
|
+
* @param res - The response or writable stream (supports .pipe(), .send(), or .write()/.end()).
|
|
97
|
+
* @returns The piped stream instance or response completion.
|
|
96
98
|
*/
|
|
97
99
|
stream(file: FileType, res: any): Promise<any>;
|
|
98
100
|
/**
|
package/dist/S3StorageAdapter.js
CHANGED
|
@@ -242,11 +242,13 @@ class S3StorageAdapter extends storage_1.AbstractStorageAdapter {
|
|
|
242
242
|
});
|
|
243
243
|
}
|
|
244
244
|
/**
|
|
245
|
-
*
|
|
245
|
+
* Fetches and streams an S3 object into an external HTTP response or writable stream.
|
|
246
|
+
* Piped directly if `res` is a Writable stream (implements `.on()`), or dispatches via `.send()` / `.write()`
|
|
247
|
+
* as a defensive fallback for non-stream response objects.
|
|
246
248
|
*
|
|
247
|
-
* @param file - Target file.
|
|
248
|
-
* @param res - The response or writable stream.
|
|
249
|
-
* @returns The piped stream instance.
|
|
249
|
+
* @param file - Target file footprint.
|
|
250
|
+
* @param res - The response or writable stream (supports .pipe(), .send(), or .write()/.end()).
|
|
251
|
+
* @returns The piped stream instance or response completion.
|
|
250
252
|
*/
|
|
251
253
|
stream(file, res) {
|
|
252
254
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -261,7 +263,16 @@ class S3StorageAdapter extends storage_1.AbstractStorageAdapter {
|
|
|
261
263
|
const readable = new node_stream_1.Readable();
|
|
262
264
|
readable.push(buffer);
|
|
263
265
|
readable.push(null);
|
|
264
|
-
|
|
266
|
+
if (typeof (res === null || res === void 0 ? void 0 : res.on) === 'function') {
|
|
267
|
+
return readable.pipe(res);
|
|
268
|
+
}
|
|
269
|
+
else if (typeof (res === null || res === void 0 ? void 0 : res.send) === 'function') {
|
|
270
|
+
return res.send(buffer);
|
|
271
|
+
}
|
|
272
|
+
else if (typeof (res === null || res === void 0 ? void 0 : res.write) === 'function' && typeof (res === null || res === void 0 ? void 0 : res.end) === 'function') {
|
|
273
|
+
res.write(buffer);
|
|
274
|
+
return res.end();
|
|
275
|
+
}
|
|
265
276
|
});
|
|
266
277
|
}
|
|
267
278
|
/**
|
package/package.json
CHANGED
package/src/S3StorageAdapter.ts
CHANGED
|
@@ -278,11 +278,13 @@ export class S3StorageAdapter extends AbstractStorageAdapter {
|
|
|
278
278
|
}
|
|
279
279
|
|
|
280
280
|
/**
|
|
281
|
-
*
|
|
281
|
+
* Fetches and streams an S3 object into an external HTTP response or writable stream.
|
|
282
|
+
* Piped directly if `res` is a Writable stream (implements `.on()`), or dispatches via `.send()` / `.write()`
|
|
283
|
+
* as a defensive fallback for non-stream response objects.
|
|
282
284
|
*
|
|
283
|
-
* @param file - Target file.
|
|
284
|
-
* @param res - The response or writable stream.
|
|
285
|
-
* @returns The piped stream instance.
|
|
285
|
+
* @param file - Target file footprint.
|
|
286
|
+
* @param res - The response or writable stream (supports .pipe(), .send(), or .write()/.end()).
|
|
287
|
+
* @returns The piped stream instance or response completion.
|
|
286
288
|
*/
|
|
287
289
|
async stream(file: FileType, res: any) {
|
|
288
290
|
const command = new GetObjectCommand({
|
|
@@ -296,7 +298,14 @@ export class S3StorageAdapter extends AbstractStorageAdapter {
|
|
|
296
298
|
readable.push(buffer)
|
|
297
299
|
readable.push(null)
|
|
298
300
|
|
|
299
|
-
|
|
301
|
+
if (typeof res?.on === 'function') {
|
|
302
|
+
return readable.pipe(res)
|
|
303
|
+
} else if (typeof res?.send === 'function') {
|
|
304
|
+
return res.send(buffer)
|
|
305
|
+
} else if (typeof res?.write === 'function' && typeof res?.end === 'function') {
|
|
306
|
+
res.write(buffer)
|
|
307
|
+
return res.end()
|
|
308
|
+
}
|
|
300
309
|
}
|
|
301
310
|
|
|
302
311
|
/**
|