Good evening.
I use to get data (pictures) busboy.
I get the data like this:
var buffer = Buffer.allocUnsafe(filesize); req.recvSize = 0; file.on('data', function (data) { buffer.write(data,req.recvSize,data.length); req.recvSize += data.length; });
The output is such an error:
buffer.js:761 return this.utf8Write(string, offset, length); ^ TypeError: Argument must be a string at TypeError (native) at Buffer.write (buffer.js:761:21)
The variant with concat does not suit me, since I initially know the file size and then I do not need unnecessary actions (because of this, I decided to immediately write to the buffer).
copy also doesn’t really want to be used, as yet write writes data directly, without unnecessary copying (if you are ready to challenge this, I will be glad to read your opinion in the comments)
How can you solve such an error or how will it be more correct to accept data?
data
argument not of typestring
, in the event handler for thefile.on
event. A must be of typestring
. - Stepan Kasyanenko