Skip to content

Commit

Permalink
feat(response): added support to Uint8Array (#540)
Browse files Browse the repository at this point in the history
Thanks again @H4ad! And thank you @Poitrin for the review and feedback
  • Loading branch information
H4ad committed Jul 25, 2022
1 parent 8cbeb30 commit 8b76331
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 0 additions & 1 deletion __tests__/integration.js
Expand Up @@ -9,7 +9,6 @@ const {
makeResponse,
EACH_MATRIX
} = require('../jest-helpers')

const jestHelpersPath = path.join(__dirname, '..', 'jest-helpers')

let app, router, serverlessExpressInstance
Expand Down
4 changes: 3 additions & 1 deletion src/response.js
Expand Up @@ -12,13 +12,15 @@ function getString (data) {
return data.toString('utf8')
} else if (typeof data === 'string') {
return data
} else if (data instanceof Uint8Array) {
return new TextDecoder().decode(data)
} else {
throw new Error(`response.write() of unexpected type: ${typeof data}`)
}
}

function addData (stream, data) {
if (Buffer.isBuffer(data) || typeof data === 'string') {
if (Buffer.isBuffer(data) || typeof data === 'string' || data instanceof Uint8Array) {
stream[BODY].push(Buffer.from(data))
} else {
throw new Error(`response.write() of unexpected type: ${typeof data}`)
Expand Down

0 comments on commit 8b76331

Please sign in to comment.