Skip to content

Commit

Permalink
fix request's arrayBuffer returning uint8 instead of arraybuffer (nod…
Browse files Browse the repository at this point in the history
  • Loading branch information
KhafraDev authored and crysmags committed Feb 27, 2024
1 parent bbd955c commit d4abe03
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/api/readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ function consumeEnd (consume) {
pos += buf.byteLength
}

resolve(dst)
resolve(dst.buffer)
} else if (type === 'blob') {
if (!Blob) {
Blob = require('buffer').Blob
Expand Down
7 changes: 5 additions & 2 deletions test/client-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ test('request blob', { skip: nodeMajor < 16 }, (t) => {
})

test('request arrayBuffer', (t) => {
t.plan(1)
t.plan(2)

const obj = { asd: true }
const server = createServer((req, res) => {
Expand All @@ -429,7 +429,10 @@ test('request arrayBuffer', (t) => {
path: '/',
method: 'GET'
})
t.strictSame(Buffer.from(JSON.stringify(obj)), Buffer.from(await body.arrayBuffer()))
const ab = await body.arrayBuffer()

t.strictSame(Buffer.from(JSON.stringify(obj)), Buffer.from(ab))
t.ok(ab instanceof ArrayBuffer)
})
})

Expand Down

0 comments on commit d4abe03

Please sign in to comment.