-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Stream is not properly ended on file -> stream #2897
Comments
Hi, thanks for the detailed report. If you hadn't seen it, the call to Lines 1060 to 1069 in 2679bb5
Making the following change to your test code seems to produce the expected output: if (process.argv[3] === "stream") {
- s.pipe(fs.createWriteStream("/dev/null"));
- finished(s, () => {
+ const w = s.pipe(fs.createWriteStream("/dev/null"));
+ finished(w, () => {
console.log(process.uptime(), "Finished");
}); ...which I think makes sense as the |
Hi, thanks for the responses. I saw that piece of code as well and tried some basic debugging, but didn't find any easy fix (or what even is the root issue). Changing the code like you suggest does work, however, I'd argue this is not the correct behavior - Node docs say it should work for readable streams as well, and even provide examples of using finalize on readable streams... I guess you can make the call if this issue should stay open as a bug. |
Making the following change, to explicitly emit the this.push(data);
}
this.push(null);
+ this.emit('close');
});
}
return this; Happy to accept a PR with this change and an associated test that would previously have failed, if you're able. |
v0.30.0 now available with the fix, thanks Drian for the PR. |
Are you using the latest version? Is the version currently in use as reported by
npm ls sharp
the same as the latest version as reported bynpm view sharp dist-tags.latest
?Yes, sharp v0.29.1
What are the steps to reproduce?
You can create a sharp instance from filename/buffer directly, or you can 'pipe' it into a sharp instance. The same goes for output - you can call
sharp.toBuffer()
, or you can use the stream API to pipe the result somewhere (though it still gets outputted in 1 large buffer/chunk, so there isn't any benefit to it. However, when you're using file input, but stream output, the stream isn't properly EOF'd -readable.push(null)
probably never happens, even though all data were already sent.Here's the output of running the code below - the
Finished
debug log doesn't appear in thefile stream
caseWhat is the expected behaviour?
The output stream pipe is properly finished even if the input is a file.
Are you able to provide a minimal, standalone code sample, without other dependencies, that demonstrates this problem?
Are you able to provide a sample image that helps explain the problem?
Not applicable (happens with multiple images i tried).
What is the output of running
npx envinfo --binaries --system
?The text was updated successfully, but these errors were encountered: