Files
bun.sh/bench/stream-file-upload-client/stream-file-node.mjs
Jarred Sumner 4c01454376 Make uploading files with fetch()fast (#3125)
* Make file uploads fast

* Add benchmark

* Update README.md

* defaults

* print

* prettier

* smaller

* fix(path) fix parse behavior (#3134)

* Add macro docs (#3139)

* Add macro doc

* Updates

* Tweaks

* Update doc

* Update macro serialization doc

* Update macro doc

* `--no-macros` flag, disable macros in node_modules

* invert base/filename internally (#3141)

* always false

* Fix broken test

* Add a test sendfile() test with large file

---------

Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Co-authored-by: Ciro Spaciari <ciro.spaciari@gmail.com>
Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>
2023-05-31 17:20:30 -07:00

20 lines
512 B
JavaScript

import { createReadStream } from "node:fs";
import http from "node:http";
console.time("stream-file-node");
createReadStream(process.env.FILE ?? "hello.txt")
.pipe(
http
.request(process.env.URL ?? "http://localhost:3000", {
method: "POST",
})
.on("response", response => {
response.on("data", data => {
console.log("Sent", parseInt(data.toString(), 10), "bytes");
});
}),
)
.on("close", () => {
console.timeEnd("stream-file-node");
});