From 4b786282a906387e071a5a28e4842a46df588c7d Mon Sep 17 00:00:00 2001 From: dcodeIO Date: Sat, 7 Jan 2017 00:56:55 +0100 Subject: [PATCH] New: Made sure that Writer#bytes is always able to handle plain arrays --- src/writer.js | 2 +- src/writer_buffer.js | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/writer.js b/src/writer.js index a9a8d9c64..17ff8089c 100644 --- a/src/writer.js +++ b/src/writer.js @@ -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. } /** diff --git a/src/writer_buffer.js b/src/writer_buffer.js index 7167b7666..59ba327f8 100644 --- a/src/writer_buffer.js +++ b/src/writer_buffer.js @@ -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++]; }; /**