Skip to content
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

Buffer concat Error with v4.2.3 #4949

Closed
calidion opened this issue Jan 29, 2016 · 3 comments
Closed

Buffer concat Error with v4.2.3 #4949

calidion opened this issue Jan 29, 2016 · 3 comments
Labels
buffer Issues and PRs related to the buffer subsystem.

Comments

@calidion
Copy link

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)

@ChALkeR
Copy link
Member

ChALkeR commented Jan 29, 2016

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

Class Method: Buffer.concat(list[, totalLength])
list Array List of Buffer objects to concat

'hello' and 'world' are not Buffer objects.

@ChALkeR ChALkeR closed this as completed Jan 29, 2016
@ChALkeR ChALkeR added the invalid Issues and PRs that are invalid. label Jan 29, 2016
@ChALkeR
Copy link
Member

ChALkeR commented Jan 29, 2016

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.

@calidion
Copy link
Author

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'.

@ChALkeR ChALkeR added buffer Issues and PRs related to the buffer subsystem. and removed invalid Issues and PRs that are invalid. labels Jan 29, 2016
@ChALkeR ChALkeR reopened this Jan 29, 2016
@targos targos added feature request Issues that request new features to be added to Node.js. and removed feature request Issues that request new features to be added to Node.js. labels Jan 29, 2016
@targos targos self-assigned this Jan 29, 2016
@Fishrock123 Fishrock123 added good first issue Issues that are suitable for first-time contributors. and removed good first issue Issues that are suitable for first-time contributors. labels Jan 29, 2016
targos added a commit to targos/node that referenced this issue Jan 31, 2016
Without this change, if any of the elements in the list to be concatenated is
not a Buffer instance, the method fails with "buf.copy is not a function".
Make an isBuffer check before using the copy method so that we can throw with
a better message.

Fixes: nodejs#4949
PR-URL: nodejs#4951
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Roman Klauke <romaaan.git@gmail.com>
rvagg pushed a commit that referenced this issue Feb 8, 2016
Without this change, if any of the elements in the list to be concatenated is
not a Buffer instance, the method fails with "buf.copy is not a function".
Make an isBuffer check before using the copy method so that we can throw with
a better message.

Fixes: #4949
PR-URL: #4951
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Roman Klauke <romaaan.git@gmail.com>
scovetta pushed a commit to scovetta/node that referenced this issue Apr 2, 2016
Without this change, if any of the elements in the list to be concatenated is
not a Buffer instance, the method fails with "buf.copy is not a function".
Make an isBuffer check before using the copy method so that we can throw with
a better message.

Fixes: nodejs#4949
PR-URL: nodejs#4951
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Roman Klauke <romaaan.git@gmail.com>
shadiakiki1986 added a commit to shadiakiki1986/node-git-rest-api that referenced this issue Nov 18, 2016
This is because Buffer.concat requires its first argument to be an array of Buffer
Check nodejs/node#4949
@targos targos removed their assignment Mar 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
buffer Issues and PRs related to the buffer subsystem.
Projects
None yet
Development

No branches or pull requests

4 participants