Comparing version 5.4.7 to 5.4.9
@@ -46,3 +46,3 @@ /* jshint browser: true, node: true */ | ||
} else { | ||
self.push(new Buffer(reader.result)); | ||
self.push(utils.bufferFrom(reader.result)); | ||
} | ||
@@ -49,0 +49,0 @@ }, false); |
@@ -161,3 +161,3 @@ /* jshint browserify: true */ | ||
var arr = md51(s); | ||
var buf = new Buffer(16); | ||
var buf = Buffer.alloc ? Buffer.alloc(16) : new Buffer(16); | ||
var i; | ||
@@ -164,0 +164,0 @@ for (i = 0; i < 4; i++) { |
@@ -50,3 +50,3 @@ /* jshint node: true */ | ||
// First 4 bytes of an Avro object container file. | ||
var MAGIC_BYTES = new Buffer('Obj\x01'); | ||
var MAGIC_BYTES = utils.bufferFrom('Obj\x01'); | ||
@@ -69,3 +69,3 @@ // Convenience. | ||
this._type = types.Type.forSchema(schema); | ||
this._tap = new Tap(new Buffer(0)); | ||
this._tap = new Tap(utils.newBuffer(0)); | ||
this._writeCb = null; | ||
@@ -138,4 +138,4 @@ this._needPush = false; | ||
this._parseHook = opts.parseHook; | ||
this._tap = new Tap(new Buffer(0)); | ||
this._blockTap = new Tap(new Buffer(0)); | ||
this._tap = new Tap(utils.newBuffer(0)); | ||
this._blockTap = new Tap(utils.newBuffer(0)); | ||
this._syncMarker = null; | ||
@@ -225,3 +225,3 @@ this._readValue = null; | ||
this._write = this._writeChunk; | ||
this._write(new Buffer(0), encoding, cb); | ||
this._write(utils.newBuffer(0), encoding, cb); | ||
}; | ||
@@ -320,3 +320,3 @@ | ||
}; | ||
this._tap = new Tap(new Buffer(opts.batchSize || 65536)); | ||
this._tap = new Tap(utils.newBuffer(opts.batchSize || 65536)); | ||
} | ||
@@ -339,3 +339,3 @@ util.inherits(RawEncoder, stream.Transform); | ||
// Not enough space for last written object, need to resize. | ||
tap.buf = new Buffer(2 * len); | ||
tap.buf = utils.newBuffer(2 * len); | ||
} | ||
@@ -400,3 +400,3 @@ tap.pos = 0; | ||
this._blockSize = opts.blockSize || 65536; | ||
this._tap = new Tap(new Buffer(this._blockSize)); | ||
this._tap = new Tap(utils.newBuffer(this._blockSize)); | ||
this._codecs = opts.codecs; | ||
@@ -466,3 +466,3 @@ this._codec = opts.codec || 'null'; | ||
this._metadata, | ||
{'avro.schema': new Buffer(schema), 'avro.codec': new Buffer(this._codec)}, | ||
{'avro.schema': utils.bufferFrom(schema), 'avro.codec': utils.bufferFrom(this._codec)}, | ||
true // Overwrite. | ||
@@ -496,3 +496,3 @@ ); | ||
} | ||
tap.buf = new Buffer(this._blockSize); | ||
tap.buf = utils.newBuffer(this._blockSize); | ||
tap.pos = 0; | ||
@@ -606,3 +606,3 @@ this._writeValue(tap, val); // Rewrite last failed write. | ||
function copyBuffer(buf, pos, len) { | ||
var copy = new Buffer(len); | ||
var copy = utils.newBuffer(len); | ||
buf.copy(copy, 0, pos, pos + len); | ||
@@ -609,0 +609,0 @@ return copy; |
@@ -36,3 +36,3 @@ /* jshint node: true */ | ||
var fd = fs.openSync(path, 'r'); | ||
var buf = new Buffer(size); | ||
var buf = utils.newBuffer(size); | ||
var pos = 0; | ||
@@ -66,3 +66,3 @@ var tap = new utils.Tap(buf); | ||
var len = 2 * tap.buf.length; | ||
var buf = new Buffer(len); | ||
var buf = utils.newBuffer(len); | ||
len = fs.readSync(fd, buf, 0, len); | ||
@@ -69,0 +69,0 @@ tap.buf = Buffer.concat([tap.buf, buf]); |
@@ -16,4 +16,30 @@ /* jshint node: true */ | ||
/** | ||
* Create a new empty buffer. | ||
* | ||
* @param size {Number} The buffer's size. | ||
*/ | ||
function newBuffer(size) { | ||
if (typeof Buffer.alloc == 'function') { | ||
return Buffer.alloc(size); | ||
} else { | ||
return new Buffer(size); | ||
} | ||
} | ||
/** | ||
* Create a new buffer with the input contents. | ||
* | ||
* @param data {Array|String} The buffer's data. | ||
* @param enc {String} Encoding, used if data is a string. | ||
*/ | ||
function bufferFrom(data, enc) { | ||
if (typeof Buffer.from == 'function') { | ||
return Buffer.from(data, enc); | ||
} else { | ||
return new Buffer(data, enc); | ||
} | ||
} | ||
/** | ||
* Uppercase the first letter of a string. | ||
@@ -244,3 +270,3 @@ * | ||
this._pos = 0; | ||
this._slab = new Buffer(this._len); | ||
this._slab = newBuffer(this._len); | ||
} | ||
@@ -251,6 +277,6 @@ | ||
if (len > maxLen) { | ||
return new Buffer(len); | ||
return newBuffer(len); | ||
} | ||
if (this._pos + len > maxLen) { | ||
this._slab = new Buffer(maxLen); | ||
this._slab = newBuffer(maxLen); | ||
this._pos = 0; | ||
@@ -328,3 +354,3 @@ } | ||
} | ||
return new Buffer(arr); | ||
return bufferFrom(arr); | ||
}; | ||
@@ -620,4 +646,7 @@ | ||
} | ||
if (len > 64) { | ||
this._writeUtf8(s, len); | ||
if (len > 64 && typeof Buffer.prototype.utf8Write == 'function') { | ||
// This method is roughly 50% faster than the manual implementation below | ||
// for long strings (which is itself faster than the generic `Buffer#write` | ||
// at least in most browsers, where `utf8Write` is not available). | ||
buf.utf8Write(s, pos, len); | ||
} else { | ||
@@ -652,14 +681,2 @@ var i, l, c1, c2; | ||
/* istanbul ignore else */ | ||
if (typeof Buffer.prototype.utf8Write == 'function') { | ||
Tap.prototype._writeUtf8 = function (str, len) { | ||
this.buf.utf8Write(str, this.pos - len, len); | ||
}; | ||
} else { | ||
// `utf8Write` isn't available in the browser. | ||
Tap.prototype._writeUtf8 = function (str, len) { | ||
this.buf.write(str, this.pos - len, len, 'utf8'); | ||
}; | ||
} | ||
/* istanbul ignore else */ | ||
if (typeof Buffer.prototype.latin1Write == 'function') { | ||
@@ -751,3 +768,3 @@ // `binaryWrite` has been renamed to `latin1Write` in Node v6.4.0, see | ||
Tap.prototype.unpackLongBytes = function () { | ||
var res = new Buffer(8); | ||
var res = newBuffer(8); | ||
var n = 0; | ||
@@ -853,2 +870,3 @@ var i = 0; // Byte index in target buffer. | ||
addDeprecatedGetters: addDeprecatedGetters, | ||
bufferFrom: bufferFrom, | ||
capitalize: capitalize, | ||
@@ -860,2 +878,3 @@ copyOwnProperties: copyOwnProperties, | ||
jsonEnd: jsonEnd, | ||
newBuffer: newBuffer, | ||
objectValues: objectValues, | ||
@@ -862,0 +881,0 @@ toMap: toMap, |
{ | ||
"name": "avsc", | ||
"version": "5.4.7", | ||
"version": "5.4.9", | ||
"description": "Avro for JavaScript", | ||
@@ -46,4 +46,5 @@ "homepage": "https://github.com/mtth/avsc", | ||
"scripts": { | ||
"cover": "istanbul cover _mocha", | ||
"clean": "rm -rf coverage dist node_modules", | ||
"cover": "nyc mocha", | ||
"coverAndPublish": "nyc npm test && nyc report --reporter=text-lcov | coveralls", | ||
"dist": "./etc/scripts/dist", | ||
@@ -55,5 +56,6 @@ "perf": "./etc/scripts/perf etc/schemas/*", | ||
"devDependencies": { | ||
"benchmark": "~2.1.4", | ||
"coveralls": "^3.0.1", | ||
"istanbul": "^0.4.5", | ||
"mocha": "^5.2.0", | ||
"nyc": "~13.3.0", | ||
"tmp": "^0.0.33" | ||
@@ -60,0 +62,0 @@ }, |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
258064
8004
5