Comparing version 2.6.2 to 2.7.0
410
bundle.js
@@ -11,2 +11,3 @@ require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({"./":[function(require,module,exports){ | ||
var ieee754 = require('ieee754') | ||
var isArray = require('is-array') | ||
@@ -16,4 +17,6 @@ exports.Buffer = Buffer | ||
exports.INSPECT_MAX_BYTES = 50 | ||
Buffer.poolSize = 8192 | ||
Buffer.poolSize = 8192 // not used by this implementation | ||
var kMaxLength = 0x3fffffff | ||
/** | ||
@@ -85,4 +88,8 @@ * If `Buffer.TYPED_ARRAY_SUPPORT`: | ||
} else | ||
throw new Error('First argument needs to be a number, array or string.') | ||
throw new TypeError('must start with number, buffer, array or string') | ||
if (this.length > kMaxLength) | ||
throw new RangeError('Attempt to allocate Buffer larger than maximum ' + | ||
'size: 0x' + kMaxLength.toString(16) + ' bytes') | ||
var buf | ||
@@ -123,5 +130,22 @@ if (Buffer.TYPED_ARRAY_SUPPORT) { | ||
// STATIC METHODS | ||
// ============== | ||
Buffer.isBuffer = function (b) { | ||
return !!(b != null && b._isBuffer) | ||
} | ||
Buffer.compare = function (a, b) { | ||
if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) | ||
throw new TypeError('Arguments must be Buffers') | ||
var x = a.length | ||
var y = b.length | ||
for (var i = 0, len = Math.min(x, y); i < len && a[i] === b[i]; i++) {} | ||
if (i !== len) { | ||
x = a[i] | ||
y = b[i] | ||
} | ||
if (x < y) return -1 | ||
if (y < x) return 1 | ||
return 0 | ||
} | ||
Buffer.isEncoding = function (encoding) { | ||
@@ -146,4 +170,27 @@ switch (String(encoding).toLowerCase()) { | ||
Buffer.isBuffer = function (b) { | ||
return !!(b != null && b._isBuffer) | ||
Buffer.concat = function (list, totalLength) { | ||
if (!isArray(list)) throw new TypeError('Usage: Buffer.concat(list[, length])') | ||
if (list.length === 0) { | ||
return new Buffer(0) | ||
} else if (list.length === 1) { | ||
return list[0] | ||
} | ||
var i | ||
if (totalLength === undefined) { | ||
totalLength = 0 | ||
for (i = 0; i < list.length; i++) { | ||
totalLength += list[i].length | ||
} | ||
} | ||
var buf = new Buffer(totalLength) | ||
var pos = 0 | ||
for (i = 0; i < list.length; i++) { | ||
var item = list[i] | ||
item.copy(buf, pos) | ||
pos += item.length | ||
} | ||
return buf | ||
} | ||
@@ -153,11 +200,4 @@ | ||
var ret | ||
str = str.toString() | ||
str = str + '' | ||
switch (encoding || 'utf8') { | ||
case 'hex': | ||
ret = str.length / 2 | ||
break | ||
case 'utf8': | ||
case 'utf-8': | ||
ret = utf8ToBytes(str).length | ||
break | ||
case 'ascii': | ||
@@ -168,5 +208,2 @@ case 'binary': | ||
break | ||
case 'base64': | ||
ret = base64ToBytes(str).length | ||
break | ||
case 'ucs2': | ||
@@ -178,4 +215,14 @@ case 'ucs-2': | ||
break | ||
case 'hex': | ||
ret = str.length >>> 1 | ||
break | ||
case 'utf8': | ||
case 'utf-8': | ||
ret = utf8ToBytes(str).length | ||
break | ||
case 'base64': | ||
ret = base64ToBytes(str).length | ||
break | ||
default: | ||
throw new Error('Unknown encoding') | ||
ret = str.length | ||
} | ||
@@ -185,50 +232,84 @@ return ret | ||
Buffer.concat = function (list, totalLength) { | ||
assert(isArray(list), 'Usage: Buffer.concat(list[, length])') | ||
// pre-set for values that may exist in the future | ||
Buffer.prototype.length = undefined | ||
Buffer.prototype.parent = undefined | ||
if (list.length === 0) { | ||
return new Buffer(0) | ||
} else if (list.length === 1) { | ||
return list[0] | ||
} | ||
// toString(encoding, start=0, end=buffer.length) | ||
Buffer.prototype.toString = function (encoding, start, end) { | ||
var loweredCase = false | ||
var i | ||
if (totalLength === undefined) { | ||
totalLength = 0 | ||
for (i = 0; i < list.length; i++) { | ||
totalLength += list[i].length | ||
start = start >>> 0 | ||
end = end === undefined || end === Infinity ? this.length : end >>> 0 | ||
if (!encoding) encoding = 'utf8' | ||
if (start < 0) start = 0 | ||
if (end > this.length) end = this.length | ||
if (end <= start) return '' | ||
while (true) { | ||
switch (encoding) { | ||
case 'hex': | ||
return hexSlice(this, start, end) | ||
case 'utf8': | ||
case 'utf-8': | ||
return utf8Slice(this, start, end) | ||
case 'ascii': | ||
return asciiSlice(this, start, end) | ||
case 'binary': | ||
return binarySlice(this, start, end) | ||
case 'base64': | ||
return base64Slice(this, start, end) | ||
case 'ucs2': | ||
case 'ucs-2': | ||
case 'utf16le': | ||
case 'utf-16le': | ||
return utf16leSlice(this, start, end) | ||
default: | ||
if (loweredCase) | ||
throw new TypeError('Unknown encoding: ' + encoding) | ||
encoding = (encoding + '').toLowerCase() | ||
loweredCase = true | ||
} | ||
} | ||
} | ||
var buf = new Buffer(totalLength) | ||
var pos = 0 | ||
for (i = 0; i < list.length; i++) { | ||
var item = list[i] | ||
item.copy(buf, pos) | ||
pos += item.length | ||
} | ||
return buf | ||
Buffer.prototype.equals = function (b) { | ||
if(!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer') | ||
return Buffer.compare(this, b) === 0 | ||
} | ||
Buffer.compare = function (a, b) { | ||
assert(Buffer.isBuffer(a) && Buffer.isBuffer(b), 'Arguments must be Buffers') | ||
var x = a.length | ||
var y = b.length | ||
for (var i = 0, len = Math.min(x, y); i < len && a[i] === b[i]; i++) {} | ||
if (i !== len) { | ||
x = a[i] | ||
y = b[i] | ||
Buffer.prototype.inspect = function () { | ||
var str = '' | ||
var max = exports.INSPECT_MAX_BYTES | ||
if (this.length > 0) { | ||
str = this.toString('hex', 0, max).match(/.{2}/g).join(' ') | ||
if (this.length > max) | ||
str += ' ... ' | ||
} | ||
if (x < y) { | ||
return -1 | ||
} | ||
if (y < x) { | ||
return 1 | ||
} | ||
return 0 | ||
return '<Buffer ' + str + '>' | ||
} | ||
// BUFFER INSTANCE METHODS | ||
// ======================= | ||
Buffer.prototype.compare = function (b) { | ||
if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer') | ||
return Buffer.compare(this, b) | ||
} | ||
// `get` will be removed in Node 0.13+ | ||
Buffer.prototype.get = function (offset) { | ||
console.log('.get() is deprecated. Access using array indexes instead.') | ||
return this.readUInt8(offset) | ||
} | ||
// `set` will be removed in Node 0.13+ | ||
Buffer.prototype.set = function (v, offset) { | ||
console.log('.set() is deprecated. Access using array indexes instead.') | ||
return this.writeUInt8(v, offset) | ||
} | ||
function hexWrite (buf, string, offset, length) { | ||
@@ -248,3 +329,3 @@ offset = Number(offset) || 0 | ||
var strLen = string.length | ||
assert(strLen % 2 === 0, 'Invalid hex string') | ||
if (strLen % 2 !== 0) throw new Error('Invalid hex string') | ||
@@ -256,3 +337,3 @@ if (length > strLen / 2) { | ||
var byte = parseInt(string.substr(i * 2, 2), 16) | ||
assert(!isNaN(byte), 'Invalid hex string') | ||
if (isNaN(byte)) throw new Error('Invalid hex string') | ||
buf[offset + i] = byte | ||
@@ -339,3 +420,3 @@ } | ||
default: | ||
throw new Error('Unknown encoding') | ||
throw new TypeError('Unknown encoding: ' + encoding) | ||
} | ||
@@ -345,43 +426,2 @@ return ret | ||
Buffer.prototype.toString = function (encoding, start, end) { | ||
var self = this | ||
encoding = String(encoding || 'utf8').toLowerCase() | ||
start = Number(start) || 0 | ||
end = (end === undefined) ? self.length : Number(end) | ||
// Fastpath empty strings | ||
if (end === start) | ||
return '' | ||
var ret | ||
switch (encoding) { | ||
case 'hex': | ||
ret = hexSlice(self, start, end) | ||
break | ||
case 'utf8': | ||
case 'utf-8': | ||
ret = utf8Slice(self, start, end) | ||
break | ||
case 'ascii': | ||
ret = asciiSlice(self, start, end) | ||
break | ||
case 'binary': | ||
ret = binarySlice(self, start, end) | ||
break | ||
case 'base64': | ||
ret = base64Slice(self, start, end) | ||
break | ||
case 'ucs2': | ||
case 'ucs-2': | ||
case 'utf16le': | ||
case 'utf-16le': | ||
ret = utf16leSlice(self, start, end) | ||
break | ||
default: | ||
throw new Error('Unknown encoding') | ||
} | ||
return ret | ||
} | ||
Buffer.prototype.toJSON = function () { | ||
@@ -394,48 +434,2 @@ return { | ||
Buffer.prototype.equals = function (b) { | ||
assert(Buffer.isBuffer(b), 'Argument must be a Buffer') | ||
return Buffer.compare(this, b) === 0 | ||
} | ||
Buffer.prototype.compare = function (b) { | ||
assert(Buffer.isBuffer(b), 'Argument must be a Buffer') | ||
return Buffer.compare(this, b) | ||
} | ||
// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length) | ||
Buffer.prototype.copy = function (target, target_start, start, end) { | ||
var source = this | ||
if (!start) start = 0 | ||
if (!end && end !== 0) end = this.length | ||
if (!target_start) target_start = 0 | ||
// Copy 0 bytes; we're done | ||
if (end === start) return | ||
if (target.length === 0 || source.length === 0) return | ||
// Fatal error conditions | ||
assert(end >= start, 'sourceEnd < sourceStart') | ||
assert(target_start >= 0 && target_start < target.length, | ||
'targetStart out of bounds') | ||
assert(start >= 0 && start < source.length, 'sourceStart out of bounds') | ||
assert(end >= 0 && end <= source.length, 'sourceEnd out of bounds') | ||
// Are we oob? | ||
if (end > this.length) | ||
end = this.length | ||
if (target.length - target_start < end - start) | ||
end = target.length - target_start + start | ||
var len = end - start | ||
if (len < 100 || !Buffer.TYPED_ARRAY_SUPPORT) { | ||
for (var i = 0; i < len; i++) { | ||
target[i + target_start] = this[i + start] | ||
} | ||
} else { | ||
target._set(this.subarray(start, start + len), target_start) | ||
} | ||
} | ||
function base64Slice (buf, start, end) { | ||
@@ -538,14 +532,2 @@ if (start === 0 && end === buf.length) { | ||
// `get` will be removed in Node 0.13+ | ||
Buffer.prototype.get = function (offset) { | ||
console.log('.get() is deprecated. Access using array indexes instead.') | ||
return this.readUInt8(offset) | ||
} | ||
// `set` will be removed in Node 0.13+ | ||
Buffer.prototype.set = function (v, offset) { | ||
console.log('.set() is deprecated. Access using array indexes instead.') | ||
return this.writeUInt8(v, offset) | ||
} | ||
/* | ||
@@ -666,5 +648,5 @@ * Need to make sure that buffer isn't trying to write out of bounds. | ||
function checkInt (buf, value, offset, ext, max, min) { | ||
assert(Buffer.isBuffer(buf), 'buffer must be a Buffer instance') | ||
assert(value <= max && value >= min, 'value is out of bounds') | ||
assert(offset + ext <= buf.length, 'index out of range') | ||
if (!Buffer.isBuffer(buf)) throw new TypeError('buffer must be a Buffer instance') | ||
if (value > max || value < min) throw new TypeError('value is out of bounds') | ||
if (offset + ext > buf.length) throw new TypeError('index out of range') | ||
} | ||
@@ -814,4 +796,4 @@ | ||
function checkIEEE754 (buf, value, offset, ext, max, min) { | ||
assert(value <= max && value >= min, 'value is out of bounds') | ||
assert(offset + ext <= buf.length, 'index out of range') | ||
if (value > max || value < min) throw new TypeError('value is out of bounds') | ||
if (offset + ext > buf.length) throw new TypeError('index out of range') | ||
} | ||
@@ -849,2 +831,38 @@ | ||
// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length) | ||
Buffer.prototype.copy = function (target, target_start, start, end) { | ||
var source = this | ||
if (!start) start = 0 | ||
if (!end && end !== 0) end = this.length | ||
if (!target_start) target_start = 0 | ||
// Copy 0 bytes; we're done | ||
if (end === start) return | ||
if (target.length === 0 || source.length === 0) return | ||
// Fatal error conditions | ||
if (end < start) throw new TypeError('sourceEnd < sourceStart') | ||
if (target_start < 0 || target_start >= target.length) | ||
throw new TypeError('targetStart out of bounds') | ||
if (start < 0 || start >= source.length) throw new TypeError('sourceStart out of bounds') | ||
if (end < 0 || end > source.length) throw new TypeError('sourceEnd out of bounds') | ||
// Are we oob? | ||
if (end > this.length) | ||
end = this.length | ||
if (target.length - target_start < end - start) | ||
end = target.length - target_start + start | ||
var len = end - start | ||
if (len < 100 || !Buffer.TYPED_ARRAY_SUPPORT) { | ||
for (var i = 0; i < len; i++) { | ||
target[i + target_start] = this[i + start] | ||
} | ||
} else { | ||
target._set(this.subarray(start, start + len), target_start) | ||
} | ||
} | ||
// fill(value, start=0, end=buffer.length) | ||
@@ -856,3 +874,3 @@ Buffer.prototype.fill = function (value, start, end) { | ||
assert(end >= start, 'end < start') | ||
if (end < start) throw new TypeError('end < start') | ||
@@ -863,4 +881,4 @@ // Fill 0 bytes; we're done | ||
assert(start >= 0 && start < this.length, 'start out of bounds') | ||
assert(end >= 0 && end <= this.length, 'end out of bounds') | ||
if (start < 0 || start >= this.length) throw new TypeError('start out of bounds') | ||
if (end < 0 || end > this.length) throw new TypeError('end out of bounds') | ||
@@ -883,15 +901,2 @@ var i | ||
Buffer.prototype.inspect = function () { | ||
var out = [] | ||
var len = this.length | ||
for (var i = 0; i < len; i++) { | ||
out[i] = toHex(this[i]) | ||
if (i === exports.INSPECT_MAX_BYTES) { | ||
out[i + 1] = '...' | ||
break | ||
} | ||
} | ||
return '<Buffer ' + out.join(' ') + '>' | ||
} | ||
/** | ||
@@ -913,3 +918,3 @@ * Creates a new `ArrayBuffer` with the *copied* memory of the buffer instance. | ||
} else { | ||
throw new Error('Buffer.toArrayBuffer not supported in this browser') | ||
throw new TypeError('Buffer.toArrayBuffer not supported in this browser') | ||
} | ||
@@ -997,8 +1002,2 @@ } | ||
function isArray (subject) { | ||
return (Array.isArray || function (subject) { | ||
return Object.prototype.toString.call(subject) === '[object Array]' | ||
})(subject) | ||
} | ||
function isArrayish (subject) { | ||
@@ -1077,7 +1076,3 @@ return isArray(subject) || Buffer.isBuffer(subject) || | ||
function assert (test, message) { | ||
if (!test) throw new Error(message || 'Failed assertion') | ||
} | ||
},{"base64-js":1,"ieee754":2}],1:[function(require,module,exports){ | ||
},{"base64-js":1,"ieee754":2,"is-array":3}],1:[function(require,module,exports){ | ||
var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; | ||
@@ -1291,3 +1286,38 @@ | ||
},{}],3:[function(require,module,exports){ | ||
/** | ||
* isArray | ||
*/ | ||
var isArray = Array.isArray; | ||
/** | ||
* toString | ||
*/ | ||
var str = Object.prototype.toString; | ||
/** | ||
* Whether or not the given `val` | ||
* is an array. | ||
* | ||
* example: | ||
* | ||
* isArray([]); | ||
* // > true | ||
* isArray(arguments); | ||
* // > false | ||
* isArray(''); | ||
* // > false | ||
* | ||
* @param {mixed} val | ||
* @return {bool} | ||
*/ | ||
module.exports = isArray || function (val) { | ||
return !! val && '[object Array]' == str.call(val); | ||
}; | ||
},{}]},{},[]); | ||
;module.exports=require("./").Buffer; |
373
index.js
@@ -10,2 +10,3 @@ /*! | ||
var ieee754 = require('ieee754') | ||
var isArray = require('is-array') | ||
@@ -15,4 +16,6 @@ exports.Buffer = Buffer | ||
exports.INSPECT_MAX_BYTES = 50 | ||
Buffer.poolSize = 8192 | ||
Buffer.poolSize = 8192 // not used by this implementation | ||
var kMaxLength = 0x3fffffff | ||
/** | ||
@@ -84,4 +87,8 @@ * If `Buffer.TYPED_ARRAY_SUPPORT`: | ||
} else | ||
throw new Error('First argument needs to be a number, array or string.') | ||
throw new TypeError('must start with number, buffer, array or string') | ||
if (this.length > kMaxLength) | ||
throw new RangeError('Attempt to allocate Buffer larger than maximum ' + | ||
'size: 0x' + kMaxLength.toString(16) + ' bytes') | ||
var buf | ||
@@ -122,5 +129,22 @@ if (Buffer.TYPED_ARRAY_SUPPORT) { | ||
// STATIC METHODS | ||
// ============== | ||
Buffer.isBuffer = function (b) { | ||
return !!(b != null && b._isBuffer) | ||
} | ||
Buffer.compare = function (a, b) { | ||
if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) | ||
throw new TypeError('Arguments must be Buffers') | ||
var x = a.length | ||
var y = b.length | ||
for (var i = 0, len = Math.min(x, y); i < len && a[i] === b[i]; i++) {} | ||
if (i !== len) { | ||
x = a[i] | ||
y = b[i] | ||
} | ||
if (x < y) return -1 | ||
if (y < x) return 1 | ||
return 0 | ||
} | ||
Buffer.isEncoding = function (encoding) { | ||
@@ -145,4 +169,27 @@ switch (String(encoding).toLowerCase()) { | ||
Buffer.isBuffer = function (b) { | ||
return !!(b != null && b._isBuffer) | ||
Buffer.concat = function (list, totalLength) { | ||
if (!isArray(list)) throw new TypeError('Usage: Buffer.concat(list[, length])') | ||
if (list.length === 0) { | ||
return new Buffer(0) | ||
} else if (list.length === 1) { | ||
return list[0] | ||
} | ||
var i | ||
if (totalLength === undefined) { | ||
totalLength = 0 | ||
for (i = 0; i < list.length; i++) { | ||
totalLength += list[i].length | ||
} | ||
} | ||
var buf = new Buffer(totalLength) | ||
var pos = 0 | ||
for (i = 0; i < list.length; i++) { | ||
var item = list[i] | ||
item.copy(buf, pos) | ||
pos += item.length | ||
} | ||
return buf | ||
} | ||
@@ -152,11 +199,4 @@ | ||
var ret | ||
str = str.toString() | ||
str = str + '' | ||
switch (encoding || 'utf8') { | ||
case 'hex': | ||
ret = str.length / 2 | ||
break | ||
case 'utf8': | ||
case 'utf-8': | ||
ret = utf8ToBytes(str).length | ||
break | ||
case 'ascii': | ||
@@ -167,5 +207,2 @@ case 'binary': | ||
break | ||
case 'base64': | ||
ret = base64ToBytes(str).length | ||
break | ||
case 'ucs2': | ||
@@ -177,4 +214,14 @@ case 'ucs-2': | ||
break | ||
case 'hex': | ||
ret = str.length >>> 1 | ||
break | ||
case 'utf8': | ||
case 'utf-8': | ||
ret = utf8ToBytes(str).length | ||
break | ||
case 'base64': | ||
ret = base64ToBytes(str).length | ||
break | ||
default: | ||
throw new Error('Unknown encoding') | ||
ret = str.length | ||
} | ||
@@ -184,50 +231,84 @@ return ret | ||
Buffer.concat = function (list, totalLength) { | ||
assert(isArray(list), 'Usage: Buffer.concat(list[, length])') | ||
// pre-set for values that may exist in the future | ||
Buffer.prototype.length = undefined | ||
Buffer.prototype.parent = undefined | ||
if (list.length === 0) { | ||
return new Buffer(0) | ||
} else if (list.length === 1) { | ||
return list[0] | ||
} | ||
// toString(encoding, start=0, end=buffer.length) | ||
Buffer.prototype.toString = function (encoding, start, end) { | ||
var loweredCase = false | ||
var i | ||
if (totalLength === undefined) { | ||
totalLength = 0 | ||
for (i = 0; i < list.length; i++) { | ||
totalLength += list[i].length | ||
start = start >>> 0 | ||
end = end === undefined || end === Infinity ? this.length : end >>> 0 | ||
if (!encoding) encoding = 'utf8' | ||
if (start < 0) start = 0 | ||
if (end > this.length) end = this.length | ||
if (end <= start) return '' | ||
while (true) { | ||
switch (encoding) { | ||
case 'hex': | ||
return hexSlice(this, start, end) | ||
case 'utf8': | ||
case 'utf-8': | ||
return utf8Slice(this, start, end) | ||
case 'ascii': | ||
return asciiSlice(this, start, end) | ||
case 'binary': | ||
return binarySlice(this, start, end) | ||
case 'base64': | ||
return base64Slice(this, start, end) | ||
case 'ucs2': | ||
case 'ucs-2': | ||
case 'utf16le': | ||
case 'utf-16le': | ||
return utf16leSlice(this, start, end) | ||
default: | ||
if (loweredCase) | ||
throw new TypeError('Unknown encoding: ' + encoding) | ||
encoding = (encoding + '').toLowerCase() | ||
loweredCase = true | ||
} | ||
} | ||
} | ||
var buf = new Buffer(totalLength) | ||
var pos = 0 | ||
for (i = 0; i < list.length; i++) { | ||
var item = list[i] | ||
item.copy(buf, pos) | ||
pos += item.length | ||
} | ||
return buf | ||
Buffer.prototype.equals = function (b) { | ||
if(!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer') | ||
return Buffer.compare(this, b) === 0 | ||
} | ||
Buffer.compare = function (a, b) { | ||
assert(Buffer.isBuffer(a) && Buffer.isBuffer(b), 'Arguments must be Buffers') | ||
var x = a.length | ||
var y = b.length | ||
for (var i = 0, len = Math.min(x, y); i < len && a[i] === b[i]; i++) {} | ||
if (i !== len) { | ||
x = a[i] | ||
y = b[i] | ||
Buffer.prototype.inspect = function () { | ||
var str = '' | ||
var max = exports.INSPECT_MAX_BYTES | ||
if (this.length > 0) { | ||
str = this.toString('hex', 0, max).match(/.{2}/g).join(' ') | ||
if (this.length > max) | ||
str += ' ... ' | ||
} | ||
if (x < y) { | ||
return -1 | ||
} | ||
if (y < x) { | ||
return 1 | ||
} | ||
return 0 | ||
return '<Buffer ' + str + '>' | ||
} | ||
// BUFFER INSTANCE METHODS | ||
// ======================= | ||
Buffer.prototype.compare = function (b) { | ||
if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer') | ||
return Buffer.compare(this, b) | ||
} | ||
// `get` will be removed in Node 0.13+ | ||
Buffer.prototype.get = function (offset) { | ||
console.log('.get() is deprecated. Access using array indexes instead.') | ||
return this.readUInt8(offset) | ||
} | ||
// `set` will be removed in Node 0.13+ | ||
Buffer.prototype.set = function (v, offset) { | ||
console.log('.set() is deprecated. Access using array indexes instead.') | ||
return this.writeUInt8(v, offset) | ||
} | ||
function hexWrite (buf, string, offset, length) { | ||
@@ -247,3 +328,3 @@ offset = Number(offset) || 0 | ||
var strLen = string.length | ||
assert(strLen % 2 === 0, 'Invalid hex string') | ||
if (strLen % 2 !== 0) throw new Error('Invalid hex string') | ||
@@ -255,3 +336,3 @@ if (length > strLen / 2) { | ||
var byte = parseInt(string.substr(i * 2, 2), 16) | ||
assert(!isNaN(byte), 'Invalid hex string') | ||
if (isNaN(byte)) throw new Error('Invalid hex string') | ||
buf[offset + i] = byte | ||
@@ -338,3 +419,3 @@ } | ||
default: | ||
throw new Error('Unknown encoding') | ||
throw new TypeError('Unknown encoding: ' + encoding) | ||
} | ||
@@ -344,43 +425,2 @@ return ret | ||
Buffer.prototype.toString = function (encoding, start, end) { | ||
var self = this | ||
encoding = String(encoding || 'utf8').toLowerCase() | ||
start = Number(start) || 0 | ||
end = (end === undefined) ? self.length : Number(end) | ||
// Fastpath empty strings | ||
if (end === start) | ||
return '' | ||
var ret | ||
switch (encoding) { | ||
case 'hex': | ||
ret = hexSlice(self, start, end) | ||
break | ||
case 'utf8': | ||
case 'utf-8': | ||
ret = utf8Slice(self, start, end) | ||
break | ||
case 'ascii': | ||
ret = asciiSlice(self, start, end) | ||
break | ||
case 'binary': | ||
ret = binarySlice(self, start, end) | ||
break | ||
case 'base64': | ||
ret = base64Slice(self, start, end) | ||
break | ||
case 'ucs2': | ||
case 'ucs-2': | ||
case 'utf16le': | ||
case 'utf-16le': | ||
ret = utf16leSlice(self, start, end) | ||
break | ||
default: | ||
throw new Error('Unknown encoding') | ||
} | ||
return ret | ||
} | ||
Buffer.prototype.toJSON = function () { | ||
@@ -393,48 +433,2 @@ return { | ||
Buffer.prototype.equals = function (b) { | ||
assert(Buffer.isBuffer(b), 'Argument must be a Buffer') | ||
return Buffer.compare(this, b) === 0 | ||
} | ||
Buffer.prototype.compare = function (b) { | ||
assert(Buffer.isBuffer(b), 'Argument must be a Buffer') | ||
return Buffer.compare(this, b) | ||
} | ||
// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length) | ||
Buffer.prototype.copy = function (target, target_start, start, end) { | ||
var source = this | ||
if (!start) start = 0 | ||
if (!end && end !== 0) end = this.length | ||
if (!target_start) target_start = 0 | ||
// Copy 0 bytes; we're done | ||
if (end === start) return | ||
if (target.length === 0 || source.length === 0) return | ||
// Fatal error conditions | ||
assert(end >= start, 'sourceEnd < sourceStart') | ||
assert(target_start >= 0 && target_start < target.length, | ||
'targetStart out of bounds') | ||
assert(start >= 0 && start < source.length, 'sourceStart out of bounds') | ||
assert(end >= 0 && end <= source.length, 'sourceEnd out of bounds') | ||
// Are we oob? | ||
if (end > this.length) | ||
end = this.length | ||
if (target.length - target_start < end - start) | ||
end = target.length - target_start + start | ||
var len = end - start | ||
if (len < 100 || !Buffer.TYPED_ARRAY_SUPPORT) { | ||
for (var i = 0; i < len; i++) { | ||
target[i + target_start] = this[i + start] | ||
} | ||
} else { | ||
target._set(this.subarray(start, start + len), target_start) | ||
} | ||
} | ||
function base64Slice (buf, start, end) { | ||
@@ -537,14 +531,2 @@ if (start === 0 && end === buf.length) { | ||
// `get` will be removed in Node 0.13+ | ||
Buffer.prototype.get = function (offset) { | ||
console.log('.get() is deprecated. Access using array indexes instead.') | ||
return this.readUInt8(offset) | ||
} | ||
// `set` will be removed in Node 0.13+ | ||
Buffer.prototype.set = function (v, offset) { | ||
console.log('.set() is deprecated. Access using array indexes instead.') | ||
return this.writeUInt8(v, offset) | ||
} | ||
/* | ||
@@ -665,5 +647,5 @@ * Need to make sure that buffer isn't trying to write out of bounds. | ||
function checkInt (buf, value, offset, ext, max, min) { | ||
assert(Buffer.isBuffer(buf), 'buffer must be a Buffer instance') | ||
assert(value <= max && value >= min, 'value is out of bounds') | ||
assert(offset + ext <= buf.length, 'index out of range') | ||
if (!Buffer.isBuffer(buf)) throw new TypeError('buffer must be a Buffer instance') | ||
if (value > max || value < min) throw new TypeError('value is out of bounds') | ||
if (offset + ext > buf.length) throw new TypeError('index out of range') | ||
} | ||
@@ -813,4 +795,4 @@ | ||
function checkIEEE754 (buf, value, offset, ext, max, min) { | ||
assert(value <= max && value >= min, 'value is out of bounds') | ||
assert(offset + ext <= buf.length, 'index out of range') | ||
if (value > max || value < min) throw new TypeError('value is out of bounds') | ||
if (offset + ext > buf.length) throw new TypeError('index out of range') | ||
} | ||
@@ -848,2 +830,38 @@ | ||
// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length) | ||
Buffer.prototype.copy = function (target, target_start, start, end) { | ||
var source = this | ||
if (!start) start = 0 | ||
if (!end && end !== 0) end = this.length | ||
if (!target_start) target_start = 0 | ||
// Copy 0 bytes; we're done | ||
if (end === start) return | ||
if (target.length === 0 || source.length === 0) return | ||
// Fatal error conditions | ||
if (end < start) throw new TypeError('sourceEnd < sourceStart') | ||
if (target_start < 0 || target_start >= target.length) | ||
throw new TypeError('targetStart out of bounds') | ||
if (start < 0 || start >= source.length) throw new TypeError('sourceStart out of bounds') | ||
if (end < 0 || end > source.length) throw new TypeError('sourceEnd out of bounds') | ||
// Are we oob? | ||
if (end > this.length) | ||
end = this.length | ||
if (target.length - target_start < end - start) | ||
end = target.length - target_start + start | ||
var len = end - start | ||
if (len < 100 || !Buffer.TYPED_ARRAY_SUPPORT) { | ||
for (var i = 0; i < len; i++) { | ||
target[i + target_start] = this[i + start] | ||
} | ||
} else { | ||
target._set(this.subarray(start, start + len), target_start) | ||
} | ||
} | ||
// fill(value, start=0, end=buffer.length) | ||
@@ -855,3 +873,3 @@ Buffer.prototype.fill = function (value, start, end) { | ||
assert(end >= start, 'end < start') | ||
if (end < start) throw new TypeError('end < start') | ||
@@ -862,4 +880,4 @@ // Fill 0 bytes; we're done | ||
assert(start >= 0 && start < this.length, 'start out of bounds') | ||
assert(end >= 0 && end <= this.length, 'end out of bounds') | ||
if (start < 0 || start >= this.length) throw new TypeError('start out of bounds') | ||
if (end < 0 || end > this.length) throw new TypeError('end out of bounds') | ||
@@ -882,15 +900,2 @@ var i | ||
Buffer.prototype.inspect = function () { | ||
var out = [] | ||
var len = this.length | ||
for (var i = 0; i < len; i++) { | ||
out[i] = toHex(this[i]) | ||
if (i === exports.INSPECT_MAX_BYTES) { | ||
out[i + 1] = '...' | ||
break | ||
} | ||
} | ||
return '<Buffer ' + out.join(' ') + '>' | ||
} | ||
/** | ||
@@ -912,3 +917,3 @@ * Creates a new `ArrayBuffer` with the *copied* memory of the buffer instance. | ||
} else { | ||
throw new Error('Buffer.toArrayBuffer not supported in this browser') | ||
throw new TypeError('Buffer.toArrayBuffer not supported in this browser') | ||
} | ||
@@ -996,8 +1001,2 @@ } | ||
function isArray (subject) { | ||
return (Array.isArray || function (subject) { | ||
return Object.prototype.toString.call(subject) === '[object Array]' | ||
})(subject) | ||
} | ||
function isArrayish (subject) { | ||
@@ -1075,5 +1074,1 @@ return isArray(subject) || Buffer.isBuffer(subject) || | ||
} | ||
function assert (test, message) { | ||
if (!test) throw new Error(message || 'Failed assertion') | ||
} |
{ | ||
"name": "buffer", | ||
"description": "Node.js Buffer API, for the browser", | ||
"version": "2.6.2", | ||
"version": "2.7.0", | ||
"author": { | ||
@@ -19,3 +19,4 @@ "name": "Feross Aboukhadijeh", | ||
"base64-js": "0.0.7", | ||
"ieee754": "^1.1.4" | ||
"ieee754": "^1.1.4", | ||
"is-array": "^1.0.1" | ||
}, | ||
@@ -22,0 +23,0 @@ "devDependencies": { |
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
505656
8952
3
+ Addedis-array@^1.0.1
+ Addedis-array@1.0.1(transitive)