You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Buffer.concat(['hello', 'world']);
TypeError: buf.copy is not a function
at Function.Buffer.concat (buffer.js:238:9)
at repl:1:8
at REPLServer.defaultEval (repl.js:248:27)
at bound (domain.js:280:14)
at REPLServer.runBound as eval
at REPLServer. (repl.js:412:12)
at emitOne (events.js:82:20)
at REPLServer.emit (events.js:169:7)
at REPLServer.Interface._onLine (readline.js:210:10)
at REPLServer.Interface._line (readline.js:549:8)
Internally, Node.js tries to call .copy method on those objects (Buffer objects have a .copy method), but there is no such method in your strings, of course. That's what the error tells you.
I would like to say that Buffer.concat should check it's arguments first before it starts to copy.
if the arguments are not what anticipated, no need to do further copy and throw an error called buf.copy is not a function.
it just makes me confused.
what more acceptable is 'String dected where Buffer is required'.
Activity
ChALkeR commentedon Jan 29, 2016
https://nodejs.org/api/buffer.html#buffer_class_method_buffer_concat_list_totallength:
'hello'and'world'are notBufferobjects.ChALkeR commentedon Jan 29, 2016
Internally, Node.js tries to call
.copymethod on those objects (Bufferobjects have a.copymethod), but there is no such method in your strings, of course. That's what the error tells you.calidion commentedon Jan 29, 2016
I would like to say that Buffer.concat should check it's arguments first before it starts to copy.
if the arguments are not what anticipated, no need to do further copy and throw an error called buf.copy is not a function.
it just makes me confused.
what more acceptable is 'String dected where Buffer is required'.
buffer: validate list elements in Buffer.concat
buffer: validate list elements in Buffer.concat
buffer: validate list elements in Buffer.concat
convert chunk to buffer before pushing to chunks