Buffer.byteLength = function (str, encoding) {
var ret
- str = str + ''
+ str = str.toString()
switch (encoding || 'utf8') {
case 'hex':
ret = str.length / 2
}
Buffer.concat = function (list, totalLength) {
- assert(isArray(list), 'Usage: Buffer.concat(list, [totalLength])\n' +
- 'list should be an Array.')
+ assert(isArray(list), 'Usage: Buffer.concat(list[, length])')
if (list.length === 0) {
return new Buffer(0)
}
var i
- if (typeof totalLength !== 'number') {
+ if (totalLength === undefined) {
totalLength = 0
for (i = 0; i < list.length; i++) {
totalLength += list[i].length
encoding = String(encoding || 'utf8').toLowerCase()
start = Number(start) || 0
- end = (end !== undefined)
- ? Number(end)
- : end = self.length
+ end = (end === undefined) ? self.length : Number(end)
// Fastpath empty strings
if (end === start)
var len = end - start
if (len < 100 || !Buffer._useTypedArrays) {
- for (var i = 0; i < len; i++)
+ for (var i = 0; i < len; i++) {
target[i + target_start] = this[i + start]
+ }
} else {
target._set(this.subarray(start, start + len), target_start)
}
var ret = ''
end = Math.min(buf.length, end)
- for (var i = start; i < end; i++)
+ for (var i = start; i < end; i++) {
ret += String.fromCharCode(buf[i])
+ }
return ret
}
var bytes = buf.slice(start, end)
var res = ''
for (var i = 0; i < bytes.length; i += 2) {
- res += String.fromCharCode(bytes[i] + bytes[i+1] * 256)
+ res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256)
}
return res
}
return (new Buffer(this)).buffer
} else {
var buf = new Uint8Array(this.length)
- for (var i = 0, len = buf.length; i < len; i += 1)
+ for (var i = 0, len = buf.length; i < len; i += 1) {
buf[i] = this[i]
+ }
return buf.buffer
}
} else {
var start = i
if (b >= 0xD800 && b <= 0xDFFF) i++
var h = encodeURIComponent(str.slice(start, i+1)).substr(1).split('%')
- for (var j = 0; j < h.length; j++)
+ for (var j = 0; j < h.length; j++) {
byteArray.push(parseInt(h[j], 16))
+ }
}
}
return byteArray