Skip to content

buffer: inconsistencies in readIntBE() and readIntLE() #10515

Closed
@Trott

Description

  • Version: 7.3.0
  • Platform: OS X 10.12.2
  • Subsystem: buffer

The documentation for readIntLE() and readIntBE() both indicate that the second argument (byteLength) is required. However, both functions will seem to operate without a byteLength provided. Unfortunately, byteLength will default to 0 in that case, which results in unpredictable behavior:

> var buf = Buffer.from([126, 127, 128, 129, 130])
undefined
> buf.readIntLE(0)
126
> buf.readIntBE(0)
undefined
> buf.readIntBE(4)
128
> buf.readIntLE(4)
129
>

Perhaps we should do one of the following?:

  • have byteLength default to 1 rather than 0
  • throw an error if byteLength is not provided
  • warn in the documentation that if you fail to provide byteLength, then you will get a result but there are no guarantees even about the return value type

Metadata

Assignees

No one assigned

    Labels

    bufferIssues and PRs related to the buffer subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions