node/lib/buffer.js

25 lines
455 B
JavaScript
Raw Normal View History

2010-03-20 11:50:29 +08:00
var Buffer = process.binding('buffer').Buffer;
exports.Buffer = Buffer;
2010-03-26 00:50:49 +08:00
function toHex (n) {
if (n < 16) return "0" + n.toString(16);
return n.toString(16);
}
2010-03-20 11:50:29 +08:00
Buffer.prototype.toString = function () {
2010-03-26 00:50:49 +08:00
var s = "<Buffer ";
for (var i = 0; i < this.length; i++) {
s += toHex(this[i]);
if (i != this.length - 1) s += ' ';
}
s += ">";
return s;
2010-03-20 11:50:29 +08:00
};
Buffer.prototype.toJSON = function () {
return this.utf8Slice(0, this.length);
};