From 34df32c3c27cefbc941214514a74f23cc24f449d Mon Sep 17 00:00:00 2001 From: Keyang Date: Sat, 7 Oct 2017 01:00:29 +0100 Subject: [PATCH] Fix encoding issue in buffer --- libs/core/Converter.js | 9 ++++++--- package.json | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/libs/core/Converter.js b/libs/core/Converter.js index 59bc836..822fb7d 100644 --- a/libs/core/Converter.js +++ b/libs/core/Converter.js @@ -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); buffer.write(str); return buffer; } @@ -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 () { diff --git a/package.json b/package.json index 296170f..0614d4e 100644 --- a/package.json +++ b/package.json @@ -244,7 +244,7 @@ "hireable": null } ], - "version": "1.1.8", + "version": "1.1.9", "keywords": [ "csv", "csv parser",