-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
Problem with buffers after upgrade from v7.5.0 to v10.7.0 #21956
Comments
Aha! It seems, no core support for unsigned 64 big endian integers. |
The errors were introduced in node v10.0.0. For proper 64-bit value support, see #19691. |
That code indeed worked fine before v10.0.0, and apparently supported all safe uint values: $ ~/tmp/nodejs/node-v6.14.1-linux-x64/bin/node
> Number.MAX_SAFE_INTEGER
9007199254740991
> x = Buffer.alloc(8, 0x42); x
<Buffer 42 42 42 42 42 42 42 42>
> x.writeUIntBE(Number.MAX_SAFE_INTEGER, 0, 8); x
<Buffer 00 1f ff ff ff ff ff ff>
> x.readUIntBE(0, 8);
9007199254740991 The docs stated «Must satisfy: |
The former behavior was somewhat undefined and risky since almost all values above We could theoretically accept higher |
Numbers between Note: I am not proposing to change that (yet), I have not thought about it much. I am just outlining things. |
…curs in node10. Actually it was a problem from the beginning, just the node10 is pickier about it. nodejs/node#21956
Given that this is documented, seems reasonable to me to close this out. Feel free to reopen if you disagree although I do think that should be accompanied by a PR if so. |
Has there been any solution if I want to read binary bigInts, such as "readIntBE(0, 8)"? |
@leimao You could do: BigInt(`0x${buf.toString('hex', 0, 8)}`); That's one of the fastest methods I found awhile back. Just be aware of possible endianness issues. |
Hello mscdex, Thanks for the quick response. The binary bigInts I am reading is from HBase. I also assume that the integer I got from HBase will not exceed the 32bit integer precision that JavaScript uses. At first I thought I could do
But later I realize that this might only work for non-negative integers. I later found an package "'node-int64'" which might be very useful to achieve my goal.
If you have any further suggestions or recommendations, please let me know. PS: I think your solution is more compatible with the future versions of NodeJS since it does not rely on external libraries and the precision of value is not likely limited to 32bit as converted from the node-in64 library. Best, Lei |
@mscdex Not sure how to apply your solution in my case const extract = tar.extract();
const gunzip = zlib.createGunzip();
var chunks = [];
extract.on('entry', function (header, stream, next) {
stream.on('data', function (chunk) {
chunks.push(chunk);
});
stream.on('end', function () {
next();
});
stream.resume();
});
extract.on('finish', async function () {
if (chunks.length) {
var data = Buffer.concat(chunks);
await writeFile(destPath, data);
consoleLogger.info("wrote %s", destPath);
}
})
.on('error', (error) => {
consoleLogger.warn("gunzip error:%@", error.toString());
})
fs.createReadStream(tmpPath)
.pipe(gunzip)
.pipe(extract) here I get a
I assume when declaring |
v10.7.0
Throws error:
Same code works fine in v7.5.0. There were some big, breaking changes without backwards compatibility ?
The text was updated successfully, but these errors were encountered: