Skip to content

Commit

Permalink
refactor: using await loop
Browse files Browse the repository at this point in the history
kudos to @Schniz
  • Loading branch information
Kikobeats committed Feb 27, 2023
1 parent 9cc1940 commit 5b81d17
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
'use strict'

const rawBody = req =>
new Promise((resolve, reject) => {
let bytes = 0
const chunks = []

req.on('error', reject)
req.on('data', chunk => {
chunks.push(chunk)
bytes += chunk.length
})

req.on('end', () => resolve(Buffer.concat(chunks, bytes)))
})
const rawBody = async req => {
const chunks = []
let bytes = 0
for await (const chunk of req) {
chunks.push(chunk)
bytes += chunk.length
}
return Buffer.concat(chunks, bytes)
}

const rawBodyMap = new WeakMap()

Expand Down

0 comments on commit 5b81d17

Please sign in to comment.