Permalink
Browse files

Added toString and toBuffer.

toString works like Buffer.prototype.toString while toBuffer is equivalent with slice().
  • Loading branch information...
1 parent 4b9ccaf commit 6cea4b9b317808a50935362f02995bf51977a5a1 David Björklund committed Oct 12, 2011
Showing with 19 additions and 0 deletions.
  1. +11 −0 README.markdown
  2. +8 −0 index.js
View
@@ -109,3 +109,14 @@ of the search. This can be used to find additional matches.
This function will return the correct result even if the search string
is spread out over multiple internal buffers.
+
+.toBuffer()
+-----------
+
+Convert the buffer collection to a single buffer, equivalent with `.slice(0, buffers.length)`;
+
+.toString(encoding, start, end)
+-----------
+
+Decodes and returns a string from the buffer collection.
+Works just like `Buffer.prototype.toString`
View
@@ -259,3 +259,11 @@ Buffers.prototype.indexOf = function (needle, offset) {
pos++;
}
};
+
+Buffers.prototype.toBuffer = function() {
+ return this.slice();
+}
+
+Buffers.prototype.toString = function(encoding, start, end) {
+ return this.slice(start, end).toString(encoding);
+}

0 comments on commit 6cea4b9

Please sign in to comment.