eip-cloud-services 1.1.6 → 1.1.7

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/s3.js +15 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eip-cloud-services",
3
- "version": "1.1.6",
3
+ "version": "1.1.7",
4
4
  "description": "Houses a collection of helpers for connecting with Cloud services.",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/s3.js CHANGED
@@ -51,6 +51,9 @@ const crypto = require ( 'crypto' );
51
51
  const { cwd } = require ( 'process' );
52
52
  const { log } = config?.s3?.logsFunction ? require ( `${ cwd ()}/${config?.s3?.logsFunction}` ) : console;
53
53
  const S3 = new S3Client ( { region: 'eu-west-1' } );
54
+ const { pipeline, Writable } = require ( 'stream' );
55
+ const util = require ( 'util' );
56
+ const pipelineAsync = util.promisify ( pipeline );
54
57
 
55
58
  /**
56
59
  * Check if an object exists in S3.
@@ -389,10 +392,16 @@ exports.listObjects = async ( prefix, bucket = config?.s3?.Bucket, continuationT
389
392
 
390
393
  exports.getClient = S3;
391
394
 
392
- const streamToBuffer = ( stream ) =>
393
- new Promise ( ( resolve, reject ) => {
394
- const chunks = [];
395
- stream.on ( 'data', ( chunk ) => chunks.push ( chunk ) );
396
- stream.on ( 'error', reject );
397
- stream.on ( 'end', () => resolve ( Buffer.concat ( chunks ) ) );
395
+ const streamToBuffer = async ( stream ) => {
396
+ const chunks = [];
397
+ const collectorStream = new Writable ( {
398
+ write ( chunk, encoding, callback ) {
399
+ chunks.push ( chunk );
400
+ callback ();
401
+ }
398
402
  } );
403
+
404
+ await pipelineAsync ( stream, collectorStream );
405
+
406
+ return Buffer.concat ( chunks );
407
+ };