You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constcontent1="this is a long long long long line";constfile1=Bun.file("./file1.txt");// not exists yetawaitBun.write(file1,content1);constfile2=Bun.file("./file2.txt");// not exists yetawaitBun.write(file2,"short line");constfile3=Bun.file("./file3.txt");// not exists yet// comment these 3 lines everything worksif(awaitfile2.exists()){awaitBun.write(file3,file2);// backup}awaitBun.write(file2,file1);awaitfile1.delete();constcontent2=awaitfile2.text();if(awaitfile3.exists()){awaitBun.write(file2,file3);awaitfile3.delete();}console.log(content1);// this is a long long long long lineconsole.log(content2);// this is a
What is the expected behavior?
write to file2 with the whole content of file1.
What do you see instead?
file 2 only contains a partial of file1.
Additional information
2025-09-07:
tried in WSL ubuntu, this same problem:
> bun run test.js
this is a long long long long line
this is a
> bun --version
1.2.22
> uname -a
Linux VM-193-107-tencentos 6.6.80-29.tl4.x86_64 #1 SMP PREEMPT_DYNAMIC Mon Mar 24 21:16:21 CST 2025 x86_64 x86_64 x86_64 GNU/Linux
#4930 is the same bug: once a BunFile's size has been resolved (.exists(), .size, or being used as a copy source), Bun.write(thatFile, otherBunFile) uses the cached size as the copy limit on the file-to-file path, which is why file2 ended up with exactly the 10 bytes of its previous contents. #4930 is the older report and was re-confirmed on 1.3.14 recently, so I'm closing this as a duplicate. Until it's fixed, use a fresh Bun.file(path) or a string path as the destination.
Activity
linear commentedon Sep 7, 2025
ENG-20330 Bun.write do short write
[-]Bun.write do short write[/-][+]Bun.write do short write when copying file[/+]terrywh commentedon Sep 18, 2025
the problem still exists in bun v1.2.22:
terrywh commentedon Oct 9, 2025
bun/1.2.23, problem persists:

terrywh commentedon Oct 11, 2025
bun/v1.3.0 problem persists:
terrywh commentedon Nov 11, 2025
bun/v1.3.2 problem persists:

terrywh commentedon Nov 28, 2025
bun/v1.3.3:
terrywh commentedon Dec 8, 2025
bun/v1.3.4:

Drop destination size cap; skip source-slice tests on Windows
Set read_len after fcopyfile on macOS
Don't let a source BunFile's cached stat size cap the copy
Bun.write: don't destroy a file copied onto itself; honour source Bun…
Bun.write: don't destroy a file copied onto itself; honour source Bun…
Bun.write: don't destroy a file copied onto itself; honour source Bun…
Bun.write: don't destroy a file copied onto itself; honour source Bun…
Jarred-Sumner commentedon Aug 13, 2026
#4930 is the same bug: once a BunFile's size has been resolved (
.exists(),.size, or being used as a copy source),Bun.write(thatFile, otherBunFile)uses the cached size as the copy limit on the file-to-file path, which is why file2 ended up with exactly the 10 bytes of its previous contents. #4930 is the older report and was re-confirmed on 1.3.14 recently, so I'm closing this as a duplicate. Until it's fixed, use a freshBun.file(path)or a string path as the destination.Duplicate of #4930
Please add a 👍 or any extra details over there so it all stays in one place. If this is actually a different problem, say so here and we'll reopen.
(This comment was written by Claude, on behalf of the Bun team.)
BunFile.existsmakesBun.writewrite nothing #4930test: a Bun.file() that was asked for its size reads, copies and uplo…