Skip to content

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

Closed
@ToPal

Description

@ToPal

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    docIssues and PRs related to the documentations.fsIssues and PRs related to the fs subsystem / file system.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions