Skip to content

Commit 034e46b

Browse files
JoseExpositoKeyang
authored andcommitted
Fixes Issue #185 (#186)
* Fixes Issue #185 Have a look to #185 for explanation * Uses var instead of let for compatibility * Changes Buffer.allocUnsafe to Buffer.alloc Even though it Buffer.allocUnsafe is documented in Node, I'm getting this error in some Node versions: ``` 2) CSV Converter should emit data event correctly: Uncaught TypeError: Buffer.allocUnsafe is not a function ``` * Adds support for very old Node.js versions
1 parent 2b677ac commit 034e46b

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

libs/core/Converter.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,16 @@ function emitDone(conv) {
8686
};
8787
}
8888
}
89-
var useBufferFrom=process.versions.node.split(".")[0]>=6;
90-
function bufFromString(str){
91-
return useBufferFrom?Buffer.from(str,"utf8"):new Buffer(str,"utf8");
89+
90+
91+
function bufFromString(str) {
92+
var buffer = Buffer.allocUnsafe
93+
? Buffer.allocUnsafe(str.length)
94+
: new Buffer(str.length);
95+
buffer.write(str);
96+
return buffer;
9297
}
98+
9399
Converter.prototype._transform = function (data, encoding, cb) {
94100
data=this.prepareData(data);
95101
var idx =data.length-1;

0 commit comments

Comments
 (0)