Skip to content

Commit

Permalink
fix(encoder): cast uint8arrays to a buffer
Browse files Browse the repository at this point in the history
Closes #13
  • Loading branch information
dignifiedquire committed May 28, 2017
1 parent b92c4e3 commit 7f34f6a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/encoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ class Encoder {
case 'Array':
return this._pushArray(this, obj)
case 'Uint8Array':
return this._pushBuffer(this, obj)
return this._pushBuffer(this, Buffer.isBuffer(obj) ? obj : new Buffer(obj))
case 'Null':
return this._pushUInt8(NULL)
case 'Undefined':
Expand Down
14 changes: 13 additions & 1 deletion test/fixtures/cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,19 @@ exports.encodeGood = [
82 -- Array, 2 items
01 -- [0], 1
02 -- [1], 2
0x820102`] // TODO: move back to good cases, once decode into set is figured out
0x820102`], // TODO: move back to good cases, once decode into set is figured out
[new Uint8Array(new Buffer(0)), "h''", `
40 -- Bytes, length: 0
0x40`],
[new Uint8Array(new Buffer('01020304', 'hex')), "h'01020304'", `
44 -- Bytes, length: 4
01020304 -- 01020304
0x4401020304`],
[new Uint8Array(new Buffer('000102030405060708090a0b0c0d0e0f101112131415161718', 'hex')), "h'000102030405060708090a0b0c0d0e0f101112131415161718'", `
58 -- Bytes, length next 1 byte
19 -- Bytes, length: 25
000102030405060708090a0b0c0d0e0f101112131415161718 -- 000102030405060708090a0b0c0d0e0f101112131415161718
0x5819000102030405060708090a0b0c0d0e0f101112131415161718`]
]

exports.decodeGood = [
Expand Down

0 comments on commit 7f34f6a

Please sign in to comment.