Permalink
Browse files

Allow explicit 0 lengths

Thus, for instance, cursor.toString('utf8',0) will return a zero-length string
instead of stringifying the rest of the buffer.  Useful to avoid edge cases
with data serialization.  undefined, null, or argument omission still indicates
read-to-end.
  • Loading branch information...
1 parent c27e18e commit cb6e9a49f3ccb0e601faca7bc8d5d74ac74fc7cd @sorear committed Dec 5, 2012
Showing with 3 additions and 3 deletions.
  1. +3 −3 buffercursor.js
View
@@ -91,7 +91,7 @@ BufferCursor.prototype.tell = function() {
BufferCursor.prototype.slice = function(length) {
var end, b;
- if (!length) {
+ if (length == undefined) {
end = this.length;
} else {
end = this._pos + length;
@@ -106,7 +106,7 @@ BufferCursor.prototype.slice = function(length) {
BufferCursor.prototype.toString = function(encoding, length) {
var end, ret;
- if (!length) {
+ if (length == undefined) {
end = this.length;
} else {
end = this._pos + length;
@@ -132,7 +132,7 @@ BufferCursor.prototype.write = function(value, length, encoding) {
BufferCursor.prototype.fill = function(value, length) {
var end;
- if (!length) {
+ if (length == undefined) {
end = this.length;
} else {
end = this._pos + length;

0 comments on commit cb6e9a4

Please sign in to comment.