|
@ -17,6 +17,21 @@ SlowBuffer.prototype.inspect = function() { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SlowBuffer.prototype.hexSlice = function(start, end) { |
|
|
|
|
|
var len = this.length; |
|
|
|
|
|
|
|
|
|
|
|
if (!start || start < 0) start = 0; |
|
|
|
|
|
if (end < 0 || start + end > len) end = len - start; |
|
|
|
|
|
|
|
|
|
|
|
var out = ''; |
|
|
|
|
|
for (var i = start; i < end; i ++) { |
|
|
|
|
|
out += toHex(this[i]); |
|
|
|
|
|
} |
|
|
|
|
|
return out; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SlowBuffer.prototype.toString = function(encoding, start, end) { |
|
|
SlowBuffer.prototype.toString = function(encoding, start, end) { |
|
|
encoding = String(encoding || 'utf8').toLowerCase(); |
|
|
encoding = String(encoding || 'utf8').toLowerCase(); |
|
|
start = +start || 0; |
|
|
start = +start || 0; |
|
@ -28,6 +43,9 @@ SlowBuffer.prototype.toString = function(encoding, start, end) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
switch (encoding) { |
|
|
switch (encoding) { |
|
|
|
|
|
case 'hex': |
|
|
|
|
|
return this.hexSlice(start, end); |
|
|
|
|
|
|
|
|
case 'utf8': |
|
|
case 'utf8': |
|
|
case 'utf-8': |
|
|
case 'utf-8': |
|
|
return this.utf8Slice(start, end); |
|
|
return this.utf8Slice(start, end); |
|
@ -51,6 +69,23 @@ SlowBuffer.prototype.toString = function(encoding, start, end) { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SlowBuffer.prototype.hexWrite = function(string, offset) { |
|
|
|
|
|
var len = string.length; |
|
|
|
|
|
offset = +offset || 0; |
|
|
|
|
|
|
|
|
|
|
|
// must be an even number of digits
|
|
|
|
|
|
if (len % 2) { |
|
|
|
|
|
throw new Error('Invalid hex string'); |
|
|
|
|
|
} |
|
|
|
|
|
for (var i = 0; i < len / 2; i ++) { |
|
|
|
|
|
var byte = parseInt(string.substr(i * 2, 2), 16); |
|
|
|
|
|
if (isNaN(byte)) throw new Error('Invalid hex string'); |
|
|
|
|
|
this[offset + i] = byte; |
|
|
|
|
|
} |
|
|
|
|
|
return i; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SlowBuffer.prototype.write = function(string, offset, encoding) { |
|
|
SlowBuffer.prototype.write = function(string, offset, encoding) { |
|
|
// Support both (string, offset, encoding)
|
|
|
// Support both (string, offset, encoding)
|
|
|
// and the legacy (string, encoding, offset)
|
|
|
// and the legacy (string, encoding, offset)
|
|
@ -64,6 +99,9 @@ SlowBuffer.prototype.write = function(string, offset, encoding) { |
|
|
encoding = String(encoding || 'utf8').toLowerCase(); |
|
|
encoding = String(encoding || 'utf8').toLowerCase(); |
|
|
|
|
|
|
|
|
switch (encoding) { |
|
|
switch (encoding) { |
|
|
|
|
|
case 'hex': |
|
|
|
|
|
return this.hexWrite(string, offset); |
|
|
|
|
|
|
|
|
case 'utf8': |
|
|
case 'utf8': |
|
|
case 'utf-8': |
|
|
case 'utf-8': |
|
|
return this.utf8Write(string, offset); |
|
|
return this.utf8Write(string, offset); |
|
@ -224,6 +262,10 @@ Buffer.prototype.write = function(string, offset, encoding) { |
|
|
|
|
|
|
|
|
var ret; |
|
|
var ret; |
|
|
switch (encoding) { |
|
|
switch (encoding) { |
|
|
|
|
|
case 'hex': |
|
|
|
|
|
ret = this.parent.hexWrite(string, this.offset + offset, maxLength); |
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
case 'utf8': |
|
|
case 'utf8': |
|
|
case 'utf-8': |
|
|
case 'utf-8': |
|
|
ret = this.parent.utf8Write(string, this.offset + offset, maxLength); |
|
|
ret = this.parent.utf8Write(string, this.offset + offset, maxLength); |
|
@ -277,6 +319,9 @@ Buffer.prototype.toString = function(encoding, start, end) { |
|
|
end = end + this.offset; |
|
|
end = end + this.offset; |
|
|
|
|
|
|
|
|
switch (encoding) { |
|
|
switch (encoding) { |
|
|
|
|
|
case 'hex': |
|
|
|
|
|
return this.parent.hexSlice(start, end); |
|
|
|
|
|
|
|
|
case 'utf8': |
|
|
case 'utf8': |
|
|
case 'utf-8': |
|
|
case 'utf-8': |
|
|
return this.parent.utf8Slice(start, end); |
|
|
return this.parent.utf8Slice(start, end); |
|
|