Browse Source

buffer: write() should always set _charsWritten.

Fixes #1633.
koichik 13 years ago
parent
commit
526c54c979
  1. 1
      lib/buffer.js
  2. 2
      test/simple/test-buffer.js

1
lib/buffer.js

@ -122,6 +122,7 @@ SlowBuffer.prototype.hexWrite = function(string, offset, length) {
if (isNaN(byte)) throw new Error('Invalid hex string'); if (isNaN(byte)) throw new Error('Invalid hex string');
this[offset + i] = byte; this[offset + i] = byte;
} }
SlowBuffer._charsWritten = i * 2;
return i; return i;
}; };

2
test/simple/test-buffer.js

@ -687,3 +687,5 @@ buf.write('0123456789', 'binary');
assert.equal(Buffer._charsWritten, 9); assert.equal(Buffer._charsWritten, 9);
buf.write('123456', 'base64'); buf.write('123456', 'base64');
assert.equal(Buffer._charsWritten, 6); assert.equal(Buffer._charsWritten, 6);
buf.write('00010203040506070809', 'hex');
assert.equal(Buffer._charsWritten, 18);

Loading…
Cancel
Save