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.readFile don't work with file descriptor #5862

Closed
ToPal opened this issue Mar 23, 2016 · 5 comments
Closed

fs.readFile don't work with file descriptor #5862

ToPal opened this issue Mar 23, 2016 · 5 comments
Labels
doc Issues and PRs related to the documentations. fs Issues and PRs related to the fs subsystem / file system.

Comments

@ToPal
Copy link

ToPal commented Mar 23, 2016

Function fs.readFile should understand both file name and file descriptor as the first argument, it's specified in docs for Node.js v4.x.

I try to use code like this:

var fs = require('fs');

var filename = './test/test.json';

fs.open(filename, 'r', function (err, fh) {
    console.log(arguments);
    fs.readFile(fh, 'utf8', function () {
        console.log(arguments);
    });
});

And I got that output:

{ '0': null, '1': 9 }
fs.js:250
  binding.open(pathModule._makeLong(path),
          ^

TypeError: path must be a string
    at TypeError (native)
    at Object.fs.readFile (fs.js:250:11)
    at /home/ubuntu/workspace/temp.js:7:8
    at FSReqWrap.oncomplete (fs.js:82:15)

My software version:

$ node --version
v4.4.1

$ uname -a
Linux topal-file_storage-2753437 4.2.0-c9 #1 SMP Fri Nov 20 14:49:01 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
@targos targos added confirmed-bug Issues with confirmed bugs. v4.x fs Issues and PRs related to the fs subsystem / file system. doc Issues and PRs related to the documentations. and removed confirmed-bug Issues with confirmed bugs. labels Mar 23, 2016
@targos
Copy link
Member

targos commented Mar 23, 2016

File descriptor support was added with #3163 and it was decided at that time not to backport this change to LTS.

This is actually an error in the documentation that was introduced by 3a8f4b2
cc @nodejs/lts @tflanagan
There could be other similar mistakes in this commit or others from the sort documentation PR

@cjihrig
Copy link
Contributor

cjihrig commented Mar 23, 2016

FWIW, I have verified that the code runs correctly on v5.

@jasnell
Copy link
Member

jasnell commented Mar 23, 2016

@targos ... good catch on that. @ToPal ... would you be interested in helping out with a PR to fix the documentation? :-)

ToPal added a commit to ToPal/node that referenced this issue Mar 23, 2016
nodejs#5862 
removed irrelevant data about fs.readFile
ToPal added a commit to ToPal/node that referenced this issue Mar 23, 2016
nodejs#5862 
removed irrelevant data about fs.readFile
@ToPal
Copy link
Author

ToPal commented Mar 23, 2016

@jasnell I would :)
Pull request for branch nodejs:v4.x is ready

ToPal added a commit to ToPal/node that referenced this issue Mar 23, 2016
nodejs#5862
removed irrelevant data about fs.readFile
@ToPal ToPal mentioned this issue Mar 23, 2016
ToPal added a commit to ToPal/node that referenced this issue Mar 24, 2016
nodejs#5862
removed irrelevant data about fs.writeFile and fs.appendFile
jasnell pushed a commit that referenced this issue Mar 24, 2016
fs.readFile, fs.writeFile and fs.appendFile doc changes
pulled back from master included details not relevant to
v4.

PR-URL: #5877
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Michaël Zasso <mic.besace@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@thefourtheye
Copy link
Contributor

Closing as #5877 landed. Thanks @ToPal :-)

MylesBorins pushed a commit that referenced this issue Mar 30, 2016
fs.readFile, fs.writeFile and fs.appendFile doc changes
pulled back from master included details not relevant to
v4.

PR-URL: #5877
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Michaël Zasso <mic.besace@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this issue Mar 30, 2016
fs.readFile, fs.writeFile and fs.appendFile doc changes
pulled back from master included details not relevant to
v4.

PR-URL: #5877
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Michaël Zasso <mic.besace@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Issues and PRs related to the documentations. fs Issues and PRs related to the fs subsystem / file system.
Projects
None yet
Development

No branches or pull requests

5 participants