Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

improvements

  • Loading branch information...
commit 17731fcb1aef0166d2f445e11f197b29aa2b4927 1 parent 4862881
@gagle authored
Showing with 9 additions and 6 deletions.
  1. +1 −1  README.md
  2. +7 −2 buffered-writer.js
  3. +1 −3 tests/buffered-writer.js
View
2  README.md
@@ -27,7 +27,7 @@ bw.open ("file")
.write ([0x00, 0x01, 0x02]) //Writes: 0x00, 0x01, 0x02
.write (new Buffer ([0x03, 0x04]), 1, 1) //Writes: 0x04
.write (0x0506) //Writes: 0x05, 0x06
- .write ("a↑b", 1) //Writes: ↑ (0xe2, 0x86, 0x91)
+ .write ("↑a", 1) //Writes: a (0x61)
.close ();
```
View
9 buffered-writer.js
@@ -129,13 +129,18 @@ Writer.prototype.write = function (buffer, offset, length){
}
offset = offset || 0;
+ var stringError;
+
var type = typeof buffer;
if (type === "number"){
buffer = toHexArray (buffer);
length = length || buffer.length - offset;
buffer = new Buffer (buffer);
}else if (type === "string"){
- length = length || Buffer.byteLength (buffer, this._encoding) - offset;
+ stringError = length - offset < 0;
+ buffer = buffer.substr (offset, length);
+ offset = 0;
+ length = Buffer.byteLength (buffer, this._encoding);
buffer = new Buffer (buffer, this._encoding);
}else if (Array.isArray (buffer)){
buffer = new Buffer (buffer);
@@ -150,7 +155,7 @@ Writer.prototype.write = function (buffer, offset, length){
return;
}
- if (length < 0){
+ if (stringError || length < 0){
var me = this;
this.close (function (){
me._error (errno.get ("INVALID_OFFSET_LENGTH", {
View
4 tests/buffered-writer.js
@@ -372,9 +372,7 @@ describe ("buffered-writer", function (){
data[3] === 0x04 &&
data[4] === 0x05 &&
data[5] === 0x06 &&
- data[6] === 0x86 &&
- data[7] === 0x91 &&
- data[8] === 0x61
+ data[6] === 0x61
);
done ();
});
Please sign in to comment.
Something went wrong with that request. Please try again.