From 515f006b6e4ddeb977580037fca6c0fbc27c3ad7 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Tue, 2 Nov 2010 10:09:59 -0700 Subject: [PATCH] Add legacy methods to Buffer --- lib/buffer.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/lib/buffer.js b/lib/buffer.js index e5539581d5..176a8fda78 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -328,3 +328,31 @@ Buffer.prototype.slice = function (start, end) { return new Buffer(this.parent, end - start, +start + this.offset); }; + + +// Legacy methods for backwards compatibility. + +Buffer.prototype.utf8Slice = function (start, end) { + return this.toString("utf8", start, end); +}; + +Buffer.prototype.binarySlice = function (start, end) { + return this.toString("binary", start, end); +}; + +Buffer.prototype.asciiSlice = function (start, end) { + return this.toString("ascii", start, end); +}; + +Buffer.prototype.utf8Write = function (string, offset) { + return this.write(string, offset, "utf8"); +}; + +Buffer.prototype.binaryWrite = function (string, offset) { + return this.write(string, offset, "binary"); +}; + +Buffer.prototype.asciiWrite = function (string, offset) { + return this.write(string, offset, "ascii"); +}; +