Node: Node.js readUIntBE arbitrary size restriction? (Docs wrong?)

Created on 24 Apr 2018  路  4Comments  路  Source: nodejs/node

Background

I am reading buffers using the Node.js buffer native API. This API has two functions called readUIntBE and readUIntLE for Big Endian and Little Endian respectively.

https://nodejs.org/api/buffer.html#buffer_buf_readuintbe_offset_bytelength_noassert

Problem

By reading the docs, I stumbled upon the following lines:

  • byteLength Number of bytes to read. Must satisfy: 0 < byteLength <= 6.

If I understand correctly, this means that I can only read 6 bytes at a time using this function, which makes it useless for my use case, as I need to read a timestamp comprised of 8 bytes.

Questions

  1. Is this a documentation typo?
  2. If not, what is the reason for such an arbitrary limitation?
  3. How do I read 8 bytes in a row ( or how do I read sequences greater than 6 bytes? )
buffer question

All 4 comments

The byteLength corresponds to e.g. 8bit, 16bit, 24bit, 32bit, 40bit and 48bit. More is not possible since JS numbers are only safe up to Number.MAX_SAFE_INTEGER.

If you want to read 8 bytes, you can read multiple entries by adding the offset.

Please always open issues like these in the https://github.com/nodejs/help repo.

I mean, it is worth pointing out that BigInt support is coming up and there鈥檚 a good chance we鈥檒l be adding support to it in Buffer methods.

I鈥檇 be okay with re-opening this as a feature request for that.

I'd prefer a new issue rather than reopening one that's a feature request hidden behind a question.

(The feature itself I'm a-okay with.)

Thank you all for the quick responses.

I genuinely thought this was a typo in the documentation, thus the reason I posted here first. Next time I will post in the link you have mention and only then, after a confirmation and if the need arises, will I post here.

I would also definitely enjoy this as a new feature, when the time comes.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ksushilmaurya picture ksushilmaurya  路  3Comments

sandeepks1 picture sandeepks1  路  3Comments

akdor1154 picture akdor1154  路  3Comments

srl295 picture srl295  路  3Comments

vsemozhetbyt picture vsemozhetbyt  路  3Comments