Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Fix RangeError caused by streamSize in encoder #120

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/encoder_stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ inherits(Encoder, Transform)

// Header = magic number + stream descriptor
Encoder.prototype.headerSize = function () {
var streamSizeSize = this.options.streamSize ? SIZES.DESCRIPTOR : 0
var streamSizeSize = this.options.streamSize ? SIZES.SIZE : 0
var dictSize = this.options.dict ? SIZES.DICTID : 0

return SIZES.MAGIC + 1 + 1 + streamSizeSize + dictSize + 1
return SIZES.MAGIC + SIZES.DESCRIPTOR + streamSizeSize + dictSize + 1
}

Encoder.prototype.header = function () {
Expand All @@ -91,8 +91,8 @@ Encoder.prototype.header = function () {
this.state = STATES.SIZE
if (this.options.streamSize) {
//TODO only 32bits size supported
descriptor.writeInt32LE(0, pos)
descriptor.writeInt32LE(this.size, pos + 4)
descriptor.writeInt32LE(this.length, pos)
descriptor.writeInt32LE(0, pos + 4)
pos += SIZES.SIZE
}
this.state = STATES.DICTID
Expand Down
9 changes: 9 additions & 0 deletions test/encode-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ describe('LZ4 encoder', function () {
})
})

describe('encoding with streamSize', function () {
it("should encode datag", function (done) {
var encoded = lz4.encode(decoded_data, { streamSize: true })

assert( compare(lz4.decode(encoded), decoded_data) )
done()
})
})

// https://github.com/pierrec/node-lz4/issues/69
describe('HC block compression', function () {
it('decoded should match with original', function (done) {
Expand Down