-
-
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
Streaming compatibility with archiver #671
Comments
Hello, I think the Something like the following should work: zip.append(resizedImageStream.resume(), { name: `${i}.png` }); Perhaps sharp's constructor jsdoc should include this information? I'd be happy to accept a PR if you'd like to make the docs clearer. |
Thanks for the reply. Adding I'll definitely add a PR if you think it would be useful. Perhaps it would be more useful in |
I can partially recreate this - the first two images in the zip file are OK but the third/last image has zero length. To investigate further we'd need to look at the internals of the archiver module to see what custom logic it uses to handle a ReadableStream instance vs what Node gives you for "free" when using |
I think I might have identified a race condition where the Writable side of a (I had a quick look at the |
Commit d8df503 adds a test and the fix for the case where the Readable side of the Duplex Stream starts flowing only after the Writable side of the Duplex Stream has emitted the "finish" event. Thanks for reporting this. |
The same issue with fix from "Commit d8df503" - 90% images have zero size :( |
@danhaller Have you been able to verify the proposed fix? |
@lovell Thanks for investigating this and sorry I haven't got back to you sooner - busy week. I've just tried the latest commit with the code example above and I'm still seeing the same problem unfortunately - the first two images are zipped correctly but any others are not. |
Do you still see the problem if you remove the ...
const zip = resizeAndZip();
zip.pipe(fs.createWriteStream(__dirname + '/output.zip'));
zip.finalize(); |
Ah I forgot to remove the Thanks again for fixing. |
Thanks @danhaller. @sinegovsky-ivan if you're still having problems, please open a new issue with a code sample that fails, preferably with error handling/logging on the streams. |
I also removed "resume" and all ok now. Thank you for your work! |
If this is complete and working fine, then 0.17.2 can be released? |
v0.17.2 now available via npm, thanks for reporting this! |
Hi,
I'm trying to use sharp's streaming capability in tandem with archiver to resize and zip multiple images and stream out to a consumer. I can get each library to work on their own, but not together on any more than a single image.
Here's some example code:
In the example you can see that I've also imported imagemagick-stream. If this library is used as the resizer instead of sharp everything works fine. I'm not sure whether this is a compatibility problem or if I'm using sharp incorrectly.
The text was updated successfully, but these errors were encountered: