Skip to content

Commit

Permalink
Fix encoding issue in buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
Keyang committed Oct 7, 2017
1 parent 6099161 commit 34df32c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions libs/core/Converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,10 @@ function emitDone(conv) {


function bufFromString(str) {
var length=Buffer.byteLength(str);
var buffer = Buffer.allocUnsafe
? Buffer.allocUnsafe(str.length)
: new Buffer(str.length);
? Buffer.allocUnsafe(length)
: new Buffer(length);

This comment has been minimized.

Copy link
@ronkorving

ronkorving Dec 7, 2017

Contributor

https://nodejs.org/docs/latest/api/buffer.html#buffer_class_method_buffer_from_string_encoding

That's a one-liner that's in Node since 5.10.0:

function bufFromString(str) {
  return Buffer.from(str);
}

This comment has been minimized.

Copy link
@Keyang

Keyang Dec 7, 2017

Author Owner

Yes but we have not considered to drop support for node 4.x even node 0.10.x

buffer.write(str);
return buffer;
}
Expand Down Expand Up @@ -530,7 +531,9 @@ Converter.prototype.transf = function (func) {

Converter.prototype.fromString = function (csvString, cb) {
if (typeof csvString !== "string") {
return cb(new Error("Passed CSV Data is not a string."));
if (cb && typeof cb ==="function"){
return cb(new Error("Passed CSV Data is not a string."));
}
}
if (cb && typeof cb === "function") {
this.wrapCallback(cb, function () {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@
"hireable": null
}
],
"version": "1.1.8",
"version": "1.1.9",
"keywords": [
"csv",
"csv parser",
Expand Down

0 comments on commit 34df32c

Please sign in to comment.