vtlab-generic-functions 1.0.7 → 1.0.8
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/package.json +1 -1
- package/s3bucket/index.js +20 -2
package/package.json
CHANGED
package/s3bucket/index.js
CHANGED
|
@@ -4,6 +4,7 @@ const config = require('../config');
|
|
|
4
4
|
const multer = require('multer');
|
|
5
5
|
const multerS3 = require('multer-s3');
|
|
6
6
|
const { promisesCollector } = require('../utils');
|
|
7
|
+
const stream = require("stream");
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Uploads a file to an S3 bucket.
|
|
@@ -106,8 +107,25 @@ const downloadFileFromS3 = async (path) => {
|
|
|
106
107
|
Key: path
|
|
107
108
|
});
|
|
108
109
|
|
|
109
|
-
|
|
110
|
-
|
|
110
|
+
try {
|
|
111
|
+
let response = await s3.send(command);
|
|
112
|
+
let Body = response.Body;
|
|
113
|
+
|
|
114
|
+
if (Body && Body instanceof stream.Readable) {
|
|
115
|
+
// Handling the stream
|
|
116
|
+
const chunks = [];
|
|
117
|
+
for await (const chunk of Body) {
|
|
118
|
+
chunks.push(chunk);
|
|
119
|
+
}
|
|
120
|
+
response.Body = Buffer.concat(chunks);
|
|
121
|
+
return response;
|
|
122
|
+
} else {
|
|
123
|
+
// If Body is not a stream, return as is
|
|
124
|
+
return response;
|
|
125
|
+
}
|
|
126
|
+
} catch (error) {
|
|
127
|
+
throw new Error(error.message);
|
|
128
|
+
}
|
|
111
129
|
} catch (error) {
|
|
112
130
|
throw error;
|
|
113
131
|
}
|