-
-
Notifications
You must be signed in to change notification settings - Fork 343
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.unshift() after end event #330
Comments
@HitkoDev Can you provide a file and description how to reproduce this issue? |
Sure: const buff = Buffer.from(whatever);
class MyStream extends Readable {
_read() {
this.push(buff);
this.push(null);
}
}
const s = new MyStream();
fileType.stream(s).then(res => console.log(res.fileType)); |
Interesting.. Our test fixtures should definitely cover this case. Did anything change with the |
@HitkoDev are you reading from your stream before calling |
@bencmbrook I'm not reading from source stream, I'm always reading from the stream returned by fileType. As I said, this usually happens when dealing with really small files, file uploads, or any other readable stream where everything is returned in a single chunk and there's nothing left after calling Line 1287 in 99beda8
|
Fixed it on my branch, thanks. Hey @sindresorhus, any chance I can get repo permissions to PR without a fork? |
@bencmbrook Oh yeah. I must have forgotten to do that previously... Done. Prefer PRs over pushing directly to master though. |
Are you taking care of this one @bencmbrook? |
@Borewit yes I have a fix, but @sindresorhus I don't think I received the access rights?
In the interest of time, my change to Line 1295 in 99beda8
to: if (readableStream.readableEnded || readableStream._readableState.ended) {
readableStream.unshift();
} else {
readableStream.unshift(chunk);
} and a test for test('.stream() method - short stream', async t => {
const buffer = Buffer.from([0, 1, 0, 1]);
class MyStream extends stream.Readable {
_read() {
this.push(buffer);
this.push(null);
}
}
const shortStream = new MyStream();
const newStream = await FileType.stream(shortStream);
t.is(newStream.fileType, undefined);
}); |
Hmm, via comments, is not really the way I guess. but it is good news you took care of the issue. Maybe push it via your cloned file-type repo? |
@bencmbrook You have to accept the invitation. |
Hah, my bad. Received, thank you. |
In some cases calling
readableStream.read
can reach the end of the stream (e.g. on a short file, or when stream emits everything in a single chunk), or stream may end for other reasons, causingreadableStream.unshift
to throw an error.The text was updated successfully, but these errors were encountered: