diff --git a/index.js b/index.js index 74e0dda..c569dde 100644 --- a/index.js +++ b/index.js @@ -2,11 +2,13 @@ var stream = require('stream') var inherits = require('inherits') var genobj = require('generate-object-property') var genfun = require('generate-function') +var bufferFrom = require('buffer-from') +var bufferAlloc = require('buffer-alloc') -var quote = new Buffer('"')[0] -var comma = new Buffer(',')[0] -var cr = new Buffer('\r')[0] -var nl = new Buffer('\n')[0] +var quote = bufferFrom('"')[0] +var comma = bufferFrom(',')[0] +var cr = bufferFrom('\r')[0] +var nl = bufferFrom('\n')[0] var Parser = function (opts) { if (!opts) opts = {} @@ -14,11 +16,11 @@ var Parser = function (opts) { stream.Transform.call(this, {objectMode: true, highWaterMark: 16}) - this.separator = opts.separator ? new Buffer(opts.separator)[0] : comma - this.quote = opts.quote ? new Buffer(opts.quote)[0] : quote - this.escape = opts.escape ? new Buffer(opts.escape)[0] : this.quote + this.separator = opts.separator ? bufferFrom(opts.separator)[0] : comma + this.quote = opts.quote ? bufferFrom(opts.quote)[0] : quote + this.escape = opts.escape ? bufferFrom(opts.escape)[0] : this.quote if (opts.newline) { - this.newline = new Buffer(opts.newline)[0] + this.newline = bufferFrom(opts.newline)[0] this.customNewline = true } else { this.newline = nl @@ -36,7 +38,7 @@ var Parser = function (opts) { this._first = true this._quoted = false this._escaped = false - this._empty = this._raw ? new Buffer(0) : '' + this._empty = this._raw ? bufferAlloc(0) : '' this._Row = null if (this.headers) { @@ -48,7 +50,7 @@ var Parser = function (opts) { inherits(Parser, stream.Transform) Parser.prototype._transform = function (data, enc, cb) { - if (typeof data === 'string') data = new Buffer(data) + if (typeof data === 'string') data = bufferFrom(data) var start = 0 var buf = data diff --git a/package.json b/package.json index 2eff20d..b827c6f 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,8 @@ "url": "git+https://github.com/mafintosh/csv-parser.git" }, "dependencies": { + "buffer-alloc": "^1.1.0", + "buffer-from": "^1.0.0", "generate-function": "^1.0.1", "generate-object-property": "^1.0.0", "inherits": "^2.0.1",