Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fs.writeFile writes garbage to file (behavior difference from node) #10219

Closed
tekknolagi opened this issue Apr 12, 2024 · 4 comments · Fixed by #10225
Closed

fs.writeFile writes garbage to file (behavior difference from node) #10219

tekknolagi opened this issue Apr 12, 2024 · 4 comments · Fixed by #10225
Assignees
Labels
bug Something isn't working node.js Compatibility with Node.js APIs

Comments

@tekknolagi
Copy link

What version of Bun is running?

1.0.25+a8ff7be64

What platform is your computer?

Linux 5.19.0-38-generic x86_64 x86_64

What steps can reproduce the bug?

https://gist.github.com/tekknolagi/3ba5c6a5bea8e87742642fbb68aba6ef

Run bun run transform.js main.js

What is the expected behavior?

main.js now contains

#!/usr/bin/env node
foo bar
const fs = require('fs');
const path = require('path');
const assert = require('assert');

(note the "foo bar")

What do you see instead?

A bunch of leading 0s:

cedar% xxd main.js 
00000000: 2300 0000 0000 0000 0000 0000 0000 0000  #...............
00000010: 0000 0000 0000 0000 0000 000a 636f 6e73  ............cons
00000020: 7420 6673 203d 2072 6571 7569 7265 2827  t fs = require('
00000030: 6673 2729 3b0a 636f 6e73 7420 7061 7468  fs');.const path
00000040: 203d 2072 6571 7569 7265 2827 7061 7468   = require('path
00000050: 2729 3b0a 636f 6e73 7420 61              ');.const a
cedar%

Additional information

No response

@tekknolagi tekknolagi added the bug Something isn't working label Apr 12, 2024
@tekknolagi
Copy link
Author

Running bun upgrade gets me to 1.1.3+2615dc742 which still has this issue.

@Electroid Electroid added the node.js Compatibility with Node.js APIs label Apr 12, 2024
@gvilums gvilums self-assigned this Apr 12, 2024
@gvilums
Copy link
Contributor

gvilums commented Apr 12, 2024

Simplified repro:

const fs = require('fs/promises');

(async () => {
  const fd = await fs.open("out.txt", "w+");
  await fd.writeFile("x");
  await fd.writeFile("x");
  await fd.close();
})();

node writes xx, bun writes x. This is probably because we're not correctly updating the file offset to write to

@tekknolagi
Copy link
Author

tekknolagi commented Apr 12, 2024 via email

@gvilums
Copy link
Contributor

gvilums commented Apr 12, 2024

Thanks for reporting the issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working node.js Compatibility with Node.js APIs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants