regular / unbzip2-stream

streaming unbzip2 implementatio in pure javascript for node and browsers
Other
29 stars 23 forks source link

Cannot read property 'bytesRead' of null #26

Closed mapo-job closed 4 years ago

mapo-job commented 5 years ago

This occur with unbzip2-stream version 1.3.3 after running few days. For an unknown reason the bitReader is null.

81: while (!broken && hasBytes > bitReader.bytesRead){ Here is the stack trace:

TypeError: Cannot read property 'bytesRead' of null
    at Stream.end (/app/tst/myApp-1.0.0/node_modules/unbzip2-stream/index.js:81:52)
    at _end (/app/tst/myApp-1.0.0/node_modules/through/index.js:65:9)
    at Stream.stream.end (/app/tst/myApp-1.0.0/node_modules/through/index.js:74:5)
    at ReadStream.onend (_stream_readable.js:655:10)
    at Object.onceWrapper (events.js:276:13)
    at ReadStream.emit (events.js:193:15)
    at endReadableNT (_stream_readable.js:1129:12)
    at process.internalTickCallback (internal/process/next_tick.js:72:19)

By the way I look at the code and not sure where the stream and this.queue is coming. For sure there is no local variable called stream.

86:                    stream.emit('error', new Error("input stream ended prematurely"));
87:                this.queue(null);
regular commented 5 years ago

@sfriesel any idea?

sfriesel commented 5 years ago

I'm not at home right now but it could happen when end() is called without a precious call to write()? Maybe an empty input stream.

regular commented 5 years ago

@mapo-job

Is it possible that you try to decompress an empty stream?

By the way I look at the code and not sure where the stream and this.queue is coming. For sure there is no local variable called stream.

Oh, there is, It's the argument to decompressAndQueue

https://github.com/regular/unbzip2-stream/blob/master/index.js#L44

mapo-job commented 5 years ago

@regular I do not read an empty stream since the file has 52K and process fine when I restarted the script.

Regarding the missing stream variable, the stream cannot come from the previous function since it belong to the function scope. To verify you can add this line: console.log(JSON.stringify(stream, null, 2)); after line 83 and you will get ReferenceError: stream is not defined

Same thing with the this.queue, it shows undefined.

sfriesel commented 5 years ago

I made a PR for stream.emit. this.queue is defined in the underlying stream object produced by through(). I don't have a good idea how bitReader could be null especially for a non-empty archive. I have an unfinished branch that replaces through with Transform (https://github.com/sfriesel/unbzip2-stream/commits/transform) that may or may not fix this issue.

sfriesel commented 4 years ago

Both parts of the issue should be fixed with version 1.4.0.