Skip to content

Commit 8b76331

Browse files
authored
feat(response): added support to Uint8Array (#540)
Thanks again @H4ad! And thank you @Poitrin for the review and feedback
1 parent 8cbeb30 commit 8b76331

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

__tests__/integration.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ const {
99
makeResponse,
1010
EACH_MATRIX
1111
} = require('../jest-helpers')
12-
1312
const jestHelpersPath = path.join(__dirname, '..', 'jest-helpers')
1413

1514
let app, router, serverlessExpressInstance

src/response.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ function getString (data) {
1212
return data.toString('utf8')
1313
} else if (typeof data === 'string') {
1414
return data
15+
} else if (data instanceof Uint8Array) {
16+
return new TextDecoder().decode(data)
1517
} else {
1618
throw new Error(`response.write() of unexpected type: ${typeof data}`)
1719
}
1820
}
1921

2022
function addData (stream, data) {
21-
if (Buffer.isBuffer(data) || typeof data === 'string') {
23+
if (Buffer.isBuffer(data) || typeof data === 'string' || data instanceof Uint8Array) {
2224
stream[BODY].push(Buffer.from(data))
2325
} else {
2426
throw new Error(`response.write() of unexpected type: ${typeof data}`)

0 commit comments

Comments
 (0)