Skip to content

Commit 9e213dc

Browse files
committed
Use Blob instead of Component in node:http example
1 parent 909fb8d commit 9e213dc

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

README.md

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,14 @@ http.createServer(async (req, res) => {
4646
if (req.method === "POST" && req.headers["content-type"]) {
4747

4848
// get the request body
49-
const chunks: Uint8Array[] = [];
49+
const body: Uint8Array[] = [];
5050
for await (const chunk of req)
51-
chunks.push(chunk);
52-
const body = Buffer.concat(chunks);
53-
54-
// create a multipart component to hold the content-type header (which includes the boundary) and the body
55-
const component = new Component({
56-
"Content-Type": req.headers["content-type"]
57-
}, body);
58-
// parse multipart from the component
59-
const multipart = Multipart.part(component);
51+
body.push(chunk);
52+
53+
// create a blob to hold the Content-Type header (which includes the boundary) and the body
54+
const blob = new Blob(body, {type: req.headers["content-type"]});
55+
// parse multipart from the blob
56+
const multipart = await Multipart.blob(blob);
6057
console.log(multipart);
6158

6259
res.end("ok");

0 commit comments

Comments
 (0)