-
Notifications
You must be signed in to change notification settings - Fork 5
.on('close') does not seem to work when using createWriteStream to send to S3 #3
Copy link
Copy link
Open
Description
This code:
var S3FS = require('@hasnat/s3fs');
const fs = require('fs');
const region = 'us-west-2';
const bucket = 'bucket';
const folder = '/folder';
const accessKeyId = '??????';
const secretAccessKey = '??????';
const options = {
region,
accessKeyId,
secretAccessKey
}
var fs3 = new S3FS(bucket, options);
process.on('uncaughtException', function (err) {
console.log('Caught exception: ' + err);
});
process.on('unhandledRejection', function (reason, promise) {
console.error('unhandled promise rejection:', reason.message || reason)
});
process.on('beforeExit', function () {
console.log('beforeExit fired')
});
process.on('exit', function () {
console.log('exit fired')
});
process.on('SIGUSR1', function () {
console.log('SIGUSR1 fired')
process.exit(1)
});
process.on('SIGTERM', function () {
console.log('SIGTERM fired')
process.exit(1)
});
process.on('SIGPIPE', function () {
console.log('SIGPIPE fired')
});
process.on('SIGHUP', function () {
console.log('SIGHUP fired')
process.exit(1)
});
process.on('SIGTERM', function () {
console.log('SIGTERM fired')
process.exit(1)
});
process.on('SIGINT', function () {
console.log('SIGINT fired')
process.exit(1)
});
process.on('SIGBREAK', function () {
console.log('SIGBREAK fired')
});
process.on('SIGWINCH', function () {
console.log('SIGWINCH fired')
});
function copyFileToS3(srcPath, dstPath) {
return new Promise((resolve, reject) => {
const rs = fs.createReadStream(srcPath);
const ws = fs3.createWriteStream(dstPath);
rs.on('close', () => {
console.log('rs.close');
});
ws.on('close', () => {
console.log('ws.close');
resolve();
});
rs.on('open', () => {
rs.pipe(ws);
});
});
}
async function doIt() {
await copyFileToS3('../_downloads/demo/case1.zip', `${folder}/case1.zip`)
const info = await fs3.readdir(folder);
console.log(JSON.stringify(info, 0, 2));
}
doIt();
Never outputs the ws.close and never calls resolve. Instead it shows the following and then exits.
beforeExit fired
exit fired
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels