Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

piped writeStream not closed on request-progress end event #36

Open
dlobsinger opened this issue Aug 25, 2017 · 0 comments
Open

piped writeStream not closed on request-progress end event #36

dlobsinger opened this issue Aug 25, 2017 · 0 comments

Comments

@dlobsinger
Copy link

I am using the request-promise library to simplify the readability of a simple file download function. I came across an issue where the piped stream throws an error when it should already have been closed.

function causing errors
function download(uri,dest){ return new Promise(function(resolve, reject){ let req = request(uri); progress(req) .on('error', function (err) { reject(err); }) .on('end', function () { resolve() }) .pipe(fs.createWriteStream(dest)); }); }

workaround by piping from the request object
function download(uri,dest){ return new Promise(function(resolve, reject){ let req = request(uri); progress(req) .on('error', function (err) { reject(err); }) .on('end', function () { resolve() }); req.pipe(fs.createWriteStream(dest)); }); }

In my scenario I am downloading the file to a temporary location, and at some point after the download function resolves the file is deleted, causing an exception:
Error: ENOENT: no such file or directory, open '/tmp/B1q5rRTOZ/ry_OPC6_Z' ^ throw er; // Unhandled stream error in pipe. internal/streams/legacy.js:59

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant