Skip to content

Commit

Permalink
Support Uint8Array values
Browse files Browse the repository at this point in the history
  • Loading branch information
jscissr authored and brianc committed Nov 4, 2017
1 parent 32537d5 commit 894e2f2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/utils.js
Expand Up @@ -50,6 +50,13 @@ var prepareValue = function (val, seen) {
if (val instanceof Buffer) {
return val
}
if (ArrayBuffer.isView(val)) {
var buf = Buffer.from(val.buffer, val.byteOffset, val.byteLength)
if (buf.length === val.byteLength) {
return buf
}
return buf.slice(val.byteOffset, val.byteOffset + val.byteLength) // Node.js v4 does not support those Buffer.from params
}
if (val instanceof Date) {
if (defaults.parseInputDatesAsUTC) {
return dateToStringUTC(val)
Expand Down
7 changes: 7 additions & 0 deletions test/unit/utils-tests.js
Expand Up @@ -53,6 +53,13 @@ test('prepareValues: buffer prepared properly', function () {
assert.strictEqual(buf, out)
})

test('prepareValues: Uint8Array prepared properly', function () {
var buf = new Uint8Array([1, 2, 3]).subarray(1, 2)
var out = utils.prepareValue(buf)
assert.ok(Buffer.isBuffer(out))
assert.deepEqual(out, [2])
})

test('prepareValues: date prepared properly', function () {
helper.setTimezoneOffset(-330)

Expand Down

0 comments on commit 894e2f2

Please sign in to comment.