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 undefined is not a function #47

Closed
kkartunov opened this issue Nov 26, 2014 · 5 comments
Closed

Buffer.concat undefined is not a function #47

kkartunov opened this issue Nov 26, 2014 · 5 comments

Comments

@kkartunov
Copy link

Hi,

in node doing Buffer.concat(...) of array of Buffers works but in the browser I get Buffer.concat undefined is not a function.

The code is like this:

...
var bodyArr = []
bodyArr.push(new Buffer('bla bla'));
bodyArr.push(new Buffer('bla2 bla2'));

var body = Buffer.concat(bodyArr);
...
req.write(body);
req.end();

I use this to create a POST body for http.
What could be the reason of this error?
I did checked that Buffer constructor is present after browserify build. But it looks that .concat method is not?

@feross
Copy link
Owner

feross commented Nov 26, 2014

Works for me. What version of browserify are you using?

@kkartunov
Copy link
Author

6.3.2 the latest i think

@kkartunov
Copy link
Author

Investigating deeper it looks that Buffer.concat() is defined indeed.
Sorry for misleading!
Dumping the array that needs to be concated I see one string item inside and multiple Uint8Array items. Could it be that the string breaks the code?

@feross
Copy link
Owner

feross commented Nov 26, 2014

Yeah, Buffer.concat takes only an array of Buffer objects, as defined by node.js. First convert the string to a Buffer and you'll be all good :)

@feross feross closed this as completed Nov 26, 2014
@kkartunov
Copy link
Author

Sure :) , thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants