Skip to content

Commit 4b78628

Browse files
committed
New: Made sure that Writer#bytes is always able to handle plain arrays
1 parent 9957b09 commit 4b78628

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/writer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ function Writer() {
121121
// list of operations to perform when finish() is called. This both allows us to allocate
122122
// buffers of the exact required size and reduces the amount of work we have to do compared
123123
// to first calculating over objects and then encoding over objects. In our case, the encoding
124-
// part is just a linked list walk calling linked operations with already prepared values.
124+
// part is just a linked list walk calling operations with already prepared values.
125125
}
126126

127127
/**

src/writer_buffer.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ var writeBytesBuffer = Buffer && Buffer.prototype instanceof Uint8Array && Buffe
3636
}
3737
/* istanbul ignore next */
3838
: function writeBytesBuffer_copy(val, buf, pos) {
39-
val.copy(buf, pos, 0, val.length);
39+
if (val.copy)
40+
val.copy(buf, pos, 0, val.length);
41+
else for (var i = 0; i < val.length;)
42+
buf[pos++] = val[i++];
4043
};
4144

4245
/**

0 commit comments

Comments
 (0)