Skip to content

Commit

Permalink
New: Made sure that Writer#bytes is always able to handle plain arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodeIO committed Jan 6, 2017
1 parent 9957b09 commit 4b78628
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ function Writer() {
// list of operations to perform when finish() is called. This both allows us to allocate
// buffers of the exact required size and reduces the amount of work we have to do compared
// to first calculating over objects and then encoding over objects. In our case, the encoding
// part is just a linked list walk calling linked operations with already prepared values.
// part is just a linked list walk calling operations with already prepared values.
}

/**
Expand Down
5 changes: 4 additions & 1 deletion src/writer_buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ var writeBytesBuffer = Buffer && Buffer.prototype instanceof Uint8Array && Buffe
}
/* istanbul ignore next */
: function writeBytesBuffer_copy(val, buf, pos) {
val.copy(buf, pos, 0, val.length);
if (val.copy)
val.copy(buf, pos, 0, val.length);
else for (var i = 0; i < val.length;)
buf[pos++] = val[i++];
};

/**
Expand Down

0 comments on commit 4b78628

Please sign in to comment.