Skip to content

Incorrect documentation or bug in Node #9165

Closed
@mrchief

Description

Per this documentation: https://nodejs.org/dist/latest-v4.x/docs/api/buffer.html#buffer_class_method_buffer_from_array
image

Buffer.from(array) was added in v3.0. However, this example (taken from docs) fails in Node v4.2.3 and Node v4.4.4

const buf = Buffer.from([0x62,0x75,0x66,0x66,0x65,0x72]);
  // creates a new Buffer containing ASCII bytes
  // ['b','u','f','f','e','r']  <-- fails in Node < v4.5.0 


// error
TypeError: this is not a typed array.
   at Function.from (native)
   at repl:1:20
   at REPLServer.defaultEval (repl.js:262:27)
   at bound (domain.js:287:14)
   at REPLServer.runBound [as eval] (domain.js:300:12)
   at REPLServer.<anonymous> (repl.js:431:12)
   at emitOne (events.js:82:20)
   at REPLServer.emit (events.js:169:7)
   at REPLServer.Interface._onLine (readline.js:211:10)
   at REPLServer.Interface._line (readline.js:550:8)

Now as per latest docs: https://nodejs.org/api/buffer.html#buffer_class_method_buffer_from_array, our friend seems to have been "added in v5.10.0"

image

And rightfully so, fails in v5.0.0

λ rpm-extract → λ git master* → node -v
v5.0.0
λ rpm-extract → λ git master* → node
> console.log(Buffer.from([0x62,0x75,0x66,0x66,0x65,0x72]))
TypeError: this is not a typed array.
    at Function.from (native)
    at repl:1:20

So, my question is:

  • Documentation is inconsistent and misleading.
  • I want to support node v4 and v6. But this intermittent behavior will cause unwanted issues for consumers who are on > 4.0 and < 5.10.0 . What's the best way to handle this?

All the tests were done using nvm on a 64 bit OSX El Capitan.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    bufferIssues and PRs related to the buffer subsystem.docIssues and PRs related to the documentations.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions