Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Uint8Array values #1448

Merged
merged 1 commit into from Nov 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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