oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.15k stars 2.77k forks source link

Writing `stdin` to a file errors with `ENOTSUP` #14054

Open lgarron opened 1 month ago

lgarron commented 1 month ago

What version of Bun is running?

1.1.26+0a37423ba

What platform is your computer?

Darwin 24.0.0 arm64 arm

What steps can reproduce the bug?

Run the following:

echo "hello world" | bun repl --eval 'await Bun.write(Bun.file("foo.txt"), Bun.stdin);'

What is the expected behavior?

bun writes the contents of stdin to foo.txt.

What do you see instead?

ENOTSUP: Operation not supported errno: -45 syscall: "fcopyfile"

Additional information

No response

lgarron commented 1 month ago

I'm guessing bun sees that both arguments are Bun.file objects and attempts to invoke a file copy syscall as an optimization under the assumption that stdin has a file path.

lgarron commented 1 month ago

There also seems to be something broken with the TypeScript types, as this does not pass type checking but is clearly correct:

import { stdin, write } from "bun";

const blob = await new Response(stdin.stream()).blob();
await write(Bun.file("foo.txt"), blob);

clipboard

clipboard

lgarron commented 1 month ago

It seems I can't take an object of type Blob and assign it to a variable of type Blob?

clipboard