-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Closed
Labels
Milestone
Description
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 by npm view sharp dist-tags.latest?
Yes, using sharp v0.29.1
What are the steps to reproduce?
This is partially related to #2897. When a sharp 'instance' is .clone()d and you attempt to consume the clone with .pipe() (native Node stream API), the stream isn't properly finalized (no matter what data input method is used for the original constructor, that's why I believe it's a separate issue.
What is the expected behaviour?
When you clone a sharp instance and specify it to drain into a pipe, it should call this.push(null) at the end to mark the stream as finished.
Are you able to provide a minimal, standalone code sample, without other dependencies, that demonstrates this problem?
import sharp from "sharp";
import fs from "node:fs";
import { createHash } from "node:crypto";
import { promisify } from "node:util";
import { finished } from "node:stream";
function sleep(x) {
return new Promise((resolve) => {
setTimeout(resolve, x);
});
}
async function hashStream(s, workaround) {
const h = createHash("sha1");
s.pipe(h);
await (workaround ? sleep(5000) : promisify(finished)(s));
return h.digest("hex");
}
(async () => {
const s = fs.createReadStream("content/main/assets/hero.jpg").pipe(sharp());
hashStream(s.clone()).then((x) => console.log("After clone, no workaround", x));
hashStream(s.clone(), true).then((x) => console.log("After clone, with sleep workaround", x));
hashStream(s).then((x) => console.log("Original, no workaround", x));
})();In the output of this code, only the latter two promises resolve and get logged (both with the same hash).
Are you able to provide a sample image that helps explain the problem?
Not relevant
What is the output of running npx envinfo --binaries --system?
System:
OS: Linux 5.4 Ubuntu 20.04.3 LTS (Focal Fossa)
CPU: (4) x64 Intel(R) Core(TM) i3-3110M CPU @ 2.40GHz
Memory: 291.26 MB / 7.35 GB
Container: Yes
Shell: 3.1.0 - /usr/bin/fish
Binaries:
Node: 14.17.6 - /usr/bin/node
Yarn: 1.22.11 - ~/.local/bin/yarn
npm: 7.21.0 - ~/.local/bin/npm
Reactions are currently unavailable