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

openSync/writeSync/closeSync produces empty file #7879

Closed
gracjan opened this issue Jul 26, 2016 · 7 comments
Closed

openSync/writeSync/closeSync produces empty file #7879

gracjan opened this issue Jul 26, 2016 · 7 comments
Labels
fs Issues and PRs related to the fs subsystem / file system.

Comments

@gracjan
Copy link

gracjan commented Jul 26, 2016

Code:

var fd = fs.openSync("abc.txt", "w");
var buf = Buffer.from("Was here.\n");
fs.writeSync(fd, buf);
fs.closeSync(fd);

produces empty file. Expected is that it writes whole buffer. Note that fs.writeSync(fd, "Was here.\n"); writes whole string.

  • Version:
    v6.2.2
  • Platform:
    Darwin MacBook-Pro-3.local 14.5.0 Darwin Kernel Version 14.5.0: Thu Apr 21 20:40:54 PDT 2016; root:xnu-2782.50.3~1/RELEASE_X86_64 x86_64
  • Subsystem:
    fs(?)
@addaleax addaleax added the fs Issues and PRs related to the fs subsystem / file system. label Jul 26, 2016
@saghul
Copy link
Member

saghul commented Jul 26, 2016

The writeSync call returns 0, which means no data was written. Didn't have time to investigate further.

@addaleax
Copy link
Member

fs.writeSync(fd, buf, 0, buf.length); should work; right now, fs.writeSync always uses the length argument, even when it’s undefined. I doubt that’s intentional, though.

@papandreou
Copy link
Contributor

Sounds like you've run into the same problem for writeSync as I did with write a few days ago: #7856

@gracjan
Copy link
Author

gracjan commented Jul 26, 2016

@papandreou: looks alike. Will the fix there also fix my issue?

@papandreou
Copy link
Contributor

I don't think it will in its current state, no. I'm on holiday for the next week, but will make sure to pick it up if noone else has landed a fix in the mean time. It's weird, seems like this bug has been there since at least 0.6. It really is the most basic form of fs.write(Sync) -- and now the two of us both discover it within half a week :)

@gracjan
Copy link
Author

gracjan commented Jul 26, 2016

@papandreou, alternatevly you could change this here

// Wrapper for write(2).
so that WriteBuffer accepts the following spec:

// Wrapper for write(2).
//
// bytesWritten = write(fd, buffer, offset, length, position, callback)
// 0 fd        integer. file descriptor
// 1 buffer    the data to write
// 2 offset    where in the buffer to start from if integer, 0 if undefined or null
// 3 length    how much to write if integer, buffer length minus offset if undefined or null
// 4 position  if integer, position to write at in the file.
//             if null or undefined, write from the current position

As I understand WriteBuffer is common meeting point for all write and writeSync functions. Thos functions could be simplified after WriteBuffer gets new functionality.

@papandreou
Copy link
Contributor

Fixed by #7856 (released in 7.2.0). This issue can be closed now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fs Issues and PRs related to the fs subsystem / file system.
Projects
None yet
Development

No branches or pull requests

5 participants