0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-30 15:30:56 +01:00
Commit Graph

6 Commits

Author SHA1 Message Date
Myles Borins
21b0a27af8
Revert "fs: make callback mandatory to all async functions"
This reverts commit 9359de9dd2.

Original Commit Message:

    The "fs" module has two functions called `maybeCallback` and
    `makeCallback`, as of now.

    The `maybeCallback` creates a default function to report errors, if the
    parameter passed is not a function object. Basically, if the callback
    is omitted in some cases, this function is used to create a default
    callback function.

    The `makeCallback`, OTOH, creates a default function only if the
    parameter passed is `undefined`, and if it is not a function object it
    will throw an `Error`.

    This patch removes the `maybeCallback` function and makes the callback
    function argument mandatory for all the async functions.

    PR-URL: https://github.com/nodejs/node/pull/7168
    Reviewed-By: Trevor Norris <trev.norris@gmail.com>

PR-URL: https://github.com/nodejs/node/pull/7846
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
2016-08-05 00:13:29 +02:00
Sakthipriyan Vairamani
9359de9dd2 fs: make callback mandatory to all async functions
The "fs" module has two functions called `maybeCallback` and
`makeCallback`, as of now.

The `maybeCallback` creates a default function to report errors, if the
parameter passed is not a function object. Basically, if the callback
is omitted in some cases, this function is used to create a default
callback function.

The `makeCallback`, OTOH, creates a default function only if the
parameter passed is `undefined`, and if it is not a function object it
will throw an `Error`.

This patch removes the `maybeCallback` function and makes the callback
function argument mandatory for all the async functions.

PR-URL: https://github.com/nodejs/node/pull/7168
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
2016-07-22 02:34:01 +05:30
James M Snell
060e5f0c00 fs: Buffer and encoding enhancements to fs API
This makes several changes:

1. Allow path/filename to be passed in as a Buffer on fs methods
2. Add `options.encoding` to fs.readdir, fs.readdirSync, fs.readlink,
   fs.readlinkSync and fs.watch.
3. Documentation updates

For 1... it's now possible to do:

```js
fs.open(Buffer('/fs/foo/bar'), 'w+', (err, fd) => { });
```

For 2...
```js
fs.readdir('/fs/foo/bar', {encoding:'hex'}, (err,list) => { });

fs.readdir('/fs/foo/bar', {encoding:'buffer'}, (err, list) => { });
```

encoding can also be passed as a string

```js
fs.readdir('/fs/foo/bar', 'hex', (err,list) => { });
```

The default encoding is set to UTF8 so this addresses the
discrepency that existed previously between fs.readdir and
fs.watch handling filenames differently.

Fixes: https://github.com/nodejs/node/issues/2088
Refs: https://github.com/nodejs/node/issues/3519
PR-URL: https://github.com/nodejs/node/pull/5616
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
2016-03-25 14:21:27 -07:00
Drew Folta
9b1bc1dd05 test: fs.link() test runs on same device
When running the tests if `NODE_TEST_DIR` is set to a device different
than the location of the test files (where this repo is checked out),
then the parallel/test-fs-link.js test will fail with
`EXDEV: cross-device link not permitted`. The code works fine (and is in
fact throwing an error as desired) but the test fails.

This commit first creates the "source" file in the same directory as the
"destination" (where the hardlink will be created).

PR-URL: https://github.com/nodejs/node/pull/4861
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Rich Trott <rtrott@gmail.com>
2016-01-26 13:53:19 +01:00
yorkie
8b97249893 fs: fix the error report on fs.link(Sync)
As the Node.js documentation specified:

> fs.link(srcpath, dstpath, callback)

But when we run:

```js
> fs.link()
```

We will get the below:

```js
TypeError: dest path must be a string
    at TypeError (native)
    at Object.fs.link (fs.js:915:11)
    at repl:1:4
```

Just correct the message of relevant 2 errors in this PR :-)

PR-URL: https://github.com/nodejs/node/pull/3917
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2015-11-20 16:09:09 -08:00
Rich Trott
1c57845118 test: fix flaky test for symlinks
If the symlink portion of the test was being skipped due to a
combination of OS support and user privileges, then an assertion would
always fail. This fixes that problem, improves assertion error reporting
and splits the test to make it clear that it is a test for links and
symlinks.

Fixes: https://github.com/nodejs/node/issues/3311
PR-URL: https://github.com/nodejs/node/pull/3418
Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
2015-10-20 09:20:21 -07:00