s3-querier 1.0.0 → 1.0.1
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/src/s3/s3.js +4 -1
package/package.json
CHANGED
package/src/s3/s3.js
CHANGED
|
@@ -368,17 +368,20 @@ export default class S3 {
|
|
|
368
368
|
*/
|
|
369
369
|
async objectToFile(key) {
|
|
370
370
|
const file = `${this.mount}/${key}`;
|
|
371
|
+
const tmp = `${file}.${process.pid}.${Date.now()}.tmp`;
|
|
371
372
|
try {
|
|
372
373
|
const response = await this.s3.send(new GetObjectCommand({ Bucket: this.bucket, Key: key }));
|
|
373
374
|
const chunks = [];
|
|
374
375
|
for await (const chunk of response.Body) {
|
|
375
376
|
chunks.push(chunk);
|
|
376
377
|
}
|
|
377
|
-
await fsPromise.writeFile(
|
|
378
|
+
await fsPromise.writeFile(tmp, Buffer.concat(chunks));
|
|
379
|
+
await fsPromise.rename(tmp, file);
|
|
378
380
|
await this.processFile(file);
|
|
379
381
|
return file;
|
|
380
382
|
} catch (error) {
|
|
381
383
|
logger.error(`${error.$metadata?.httpStatusCode ?? error.statusCode} - ${file}`);
|
|
384
|
+
await fsPromise.unlink(tmp).catch(() => {});
|
|
382
385
|
throw error;
|
|
383
386
|
}
|
|
384
387
|
}
|