GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fs: readdir optionally returning type information by bengl · Pull Request #22020 · nodejs/node

Conversation

@bengl

@bengl bengl commented Jul 29, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

readdir and readdirSync now have a "withFileTypes" option, which, when enabled,
provides an array of DirectoryEntry objects, similar to Stats bjects,
which have the filename and the type information.

Ref: #15699

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

izolate and danielbayley reacted with thumbs up emoji
All reactions
  • 👍 2 reactions
@nodejs-github-bot

nodejs-github-bot commented Jul 29, 2018

Copy link
Copy Markdown
Collaborator

@bengl build started: https://ci.nodejs.org/blue/organizations/jenkins/node-test-pull-request-lite-pipeline/detail/node-test-pull-request-lite-pipeline/376/pipeline

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs involving general changes in the lib/ or src/ directories. labels Jul 29, 2018
@bengl bengl added the fs Issues and PRs related to file-system APIs and the fs module. label Jul 29, 2018
mscdex
mscdex reviewed Jul 29, 2018
View reviewed changes
Comment thread src/node_file.cc Outdated

@mscdex mscdex Jul 29, 2018

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know at one time V8 would optimize the case for arrays where each element was of the same type. Perhaps this might perform better if we had a separate array for the type values? That would also allow us to avoid having to i \ 2 inside the JS loop, which is slower than just referencing i.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
addaleax
addaleax reviewed Jul 29, 2018
View reviewed changes
Comment thread doc/api/fs.md Outdated

@addaleax addaleax Jul 29, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Expand this to withFileTypes, since types can refer to a bunch of different things in a programming context

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread doc/api/fs.md Outdated

This comment was marked as resolved.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/node_file.cc Outdated

@addaleax addaleax Jul 29, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Maybe do the reverse condition and return, to save one level of indentation for the rest of the function?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/node_file.cc Outdated

@addaleax addaleax Jul 29, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is what we do for existing code, but do you mind moving to proper error-checking here? (i.e. return if the Call result is empty like you do below)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
vsemozhetbyt
vsemozhetbyt reviewed Jul 29, 2018
View reviewed changes
Comment thread doc/api/fs.md Outdated

@vsemozhetbyt vsemozhetbyt Jul 29, 2018

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Missing YAML?
  2. It seems this property should be the last one, ABC-wise.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
vsemozhetbyt
vsemozhetbyt reviewed Jul 29, 2018
View reviewed changes
Comment thread doc/api/fs.md Outdated

@vsemozhetbyt vsemozhetbyt Jul 29, 2018

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exceeds 80 characters length.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
vsemozhetbyt
vsemozhetbyt reviewed Jul 29, 2018
View reviewed changes
Comment thread doc/api/fs.md Outdated

@vsemozhetbyt vsemozhetbyt Jul 29, 2018

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exceeds 80 characters length.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bengl

bengl commented Jul 30, 2018

Copy link
Copy Markdown
Member Author

@addaleax @vsemozhetbyt I added a squash commit which I think addresses your comments. PTAL.

@mscdex What would be better as a return value: an array of arrays like [[name1, name2, ...], [type1, type2, ...]] or an object containing both arrays? Or an array of { name, type } objects?

vsemozhetbyt reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Trott Trott added the semver-minor PRs that contain new features and should be released in the next minor version. label Jul 30, 2018
@bengl

bengl commented Jul 30, 2018

Copy link
Copy Markdown
Member Author

CI: https://ci.nodejs.org/job/node-test-pull-request/16072/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Trott

Trott commented Jul 30, 2018

Copy link
Copy Markdown
Member

@nodejs/fs

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Trott

Trott commented Jul 30, 2018

Copy link
Copy Markdown
Member

Since documentation additions are significant: @nodejs/documentation

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@devsnek

devsnek commented Jul 30, 2018

Copy link
Copy Markdown
Member

why don't we just add scandir and scandirSync so we don't have to deal with polymorphic return types and weird options

also +1 to { name, type }, the whole stats object thing is terrible

ronkorving, YurySolovyov, and benjamingr reacted with thumbs up emoji
All reactions
  • 👍 3 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mscdex

mscdex commented Jul 30, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

What would be better as a return value: an array of arrays like [[name1, name2, ...], [type1, type2, ...]] or an object containing both arrays? Or an array of { name, type } objects?

I would guess it's still faster to create objects in JS land, but what I was suggesting is to pass back two separate arrays to req.oncomplete(). You could even reuse one of the arrays for the return value:

req.oncomplete = (err, names, fileTypes) => {
  if (err) {
    callback(err);
    return;
  }
  const len = names.length;
  for (var i = 0; i < len; ++i)
    names[i] = new DirectoryEntry(names[i], fileTypes[i]);
  callback(null, names);
};

I'm not sure what V8 does optimization-wise when reusing the array like that, if it re-optimizes after the loop finishes or what, but that's the general idea I had in mind.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ronkorving

ronkorving commented Jul 30, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

I'm definitely with @devsnek on making these separate API. Having one API return completely different things based on options is .. a bit too much. Different input format causing a different output format... At that point, I think it has just become a different function. Also, the name scandir as @devsnek suggests feels very natural to me.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bengl

bengl commented Jul 30, 2018

Copy link
Copy Markdown
Member Author

@mscdex Right, that would make sense for the async case, but for the sync case, since a single value needs to be returned from the binding function, something holding both arrays is needed.

@devsnek

why don't we just add scandir and scandirSync so we don't have to deal with polymorphic return types and weird options

I had originally planned on doing it that way (as suggested in the linked issue), but most functions on fs, including readdir/readdirSync define themselves in terms of UNIX man pages. In there, scandir is defined as "scan a directory for matching entries", wheras what's happening here is far closer to readdir. I'd rather reserve scandir for when something that closer matches it is implemented. (Note: I'm not necessarily a big fan of having such a POSIX-centric fs module, but it's what we have, and my intention was to not stray too far from it.)

also +1 to { name, type }, the whole stats object thing is terrible

I did the Stats-esque DirectoryEntry object deliberately to be consistent with the stat functions, since any use case of this new feature was previously worked around by calling stat on each entry returned by readdir/readdirSync. Also, the type is a number, and I didn't think it was best to either convert it on the fly to something readable or force the comparison onto the user.

All that being said: If there's consensus around scandir/scandirSync, bare-object-dirents, or any other significant changes to the API I've presented here, I'm happy to make those changes.

benjamingr reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mscdex

mscdex commented Jul 30, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

but for the sync case, since a single value needs to be returned from the binding function, something holding both arrays is needed.

A 2-D array would probably work for that case.

Perhaps an even better solution that would work for both scenarios would be to create the zero-length arrays in JS land and pass them (via the context object) to C++ land and fill them in there. Then do the same process as I showed in the code snippet earlier.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bengl

bengl commented Jul 30, 2018

Copy link
Copy Markdown
Member Author

@mscdex Since the async version seems to be all set up to handle both callbacks and promises in C++, it seemed easier to just have a 2-D array in all cases, which I've done in the latest squash commit.


And another CI run...

CI: https://ci.nodejs.org/job/node-test-pull-request/16073/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

BridgeAR
BridgeAR approved these changes Jul 30, 2018
View reviewed changes

@BridgeAR BridgeAR left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Just some nits that do not block the PR. I only roughly looked at the C++ part.
I have no strong opinion about it being a new API or not.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread test/parallel/test-fs-readdir-types.js Outdated

@BridgeAR BridgeAR Jul 30, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: assert.strictEqual(dirent[testMethod](), testMethod === method);

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/internal/fs/promises.js Outdated

@BridgeAR BridgeAR Jul 30, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe move this part into fs/utils.js? It is done three times and could use the abstraction.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/fs.js Outdated

@BridgeAR BridgeAR Jul 30, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super tiny nit: the else could be removed to reduce indentation. The same in other places.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bengl

bengl commented Jul 30, 2018

Copy link
Copy Markdown
Member Author

I'm not sure what the AIX and SmartOS errors are all about. It seems like isFile isn't working on those systems? That's pretty weird. Maybe the values for the types are not in the set defined by libuv?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bengl

bengl commented Jul 31, 2018

Copy link
Copy Markdown
Member Author

Here's another CI run, hopefully fixing AIX and SmartOS...

CI: https://ci.nodejs.org/job/node-test-pull-request/16088/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bengl

bengl commented Jul 31, 2018

Copy link
Copy Markdown
Member Author

One more CI, hopefully passing this time...

CI: https://ci.nodejs.org/job/node-test-pull-request/16089/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Trott

Trott commented Aug 1, 2018

Copy link
Copy Markdown
Member

Resume Build: https://ci.nodejs.org/job/node-test-pull-request/16109/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bengl

bengl commented Aug 1, 2018

Copy link
Copy Markdown
Member Author

Since this introduces a binding-layer breaking change....

CITGM: https://ci.nodejs.org/view/Node.js-citgm/job/citgm-smoker/1480/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jasnell
jasnell approved these changes Aug 1, 2018
View reviewed changes
@bengl
bengl force-pushed the readdirtypes branch from 0699921 to 021bf1f Compare August 1, 2018 19:15
@bengl

bengl commented Aug 1, 2018

Copy link
Copy Markdown
Member Author

Rebased to deal with FSReqWrap -> FSReqCallback from @maclover7.

New CI: https://ci.nodejs.org/job/node-test-pull-request/16131/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bengl

bengl commented Aug 1, 2018

Copy link
Copy Markdown
Member Author

Post-rebase-fix CI: https://ci.nodejs.org/job/node-test-pull-request/16134/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@BridgeAR BridgeAR mentioned this pull request Aug 17, 2018
Feature request: Autocomplete filenames for fs functions in repl #17764
Closed
@targos targos added backport-requested-v10.x and removed author ready PRs with CI started, the required approvals, and no outstanding review comments. backport-requested-v10.x labels Aug 19, 2018
targos pushed a commit that referenced this pull request Aug 19, 2018
@bengl @targos
fs: readdir optionally returning type information
549d0c2
readdir and readdirSync now have a "withFileTypes" option, which, when
enabled, provides an array of DirectoryEntry objects, similar to Stats
objects, which have the filename and the type information.

Refs: #15699

PR-URL: #22020
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Roman Reiss <[email protected]>
Reviewed-By: John-David Dalton <[email protected]>
@silverwind silverwind mentioned this pull request Sep 2, 2018
readdir should have {type:'file'} option - should allow user to only retrieve files not folders etc #21804
Closed
targos pushed a commit that referenced this pull request Sep 3, 2018
@bengl @targos
fs: readdir optionally returning type information
ad97314
readdir and readdirSync now have a "withFileTypes" option, which, when
enabled, provides an array of DirectoryEntry objects, similar to Stats
objects, which have the filename and the type information.

Refs: #15699

PR-URL: #22020
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Roman Reiss <[email protected]>
Reviewed-By: John-David Dalton <[email protected]>
targos added a commit that referenced this pull request Sep 5, 2018
@targos
2018-09-06, Version 10.10.0 (Current)
8a45a6c
Notable changes:

* child_process:
  * `TypedArray` and `DataView` values are now accepted as input by
    `execFileSync` and `spawnSync`. #22409
* coverage:
  * Native V8 code coverage information can now be output to disk by setting the
    environment variable `NODE_V8_COVERAGE` to a directory. #22527
* deps:
  * The bundled npm was upgraded to version 6.4.1. #22591
    * Changelogs:
      [6.3.0-next.0](https://github.com/npm/cli/releases/tag/v6.3.0-next.0)
      [6.3.0](https://github.com/npm/cli/releases/tag/v6.3.0)
      [6.4.0](https://github.com/npm/cli/releases/tag/v6.4.0)
      [6.4.1](https://github.com/npm/cli/releases/tag/v6.4.1)
* fs:
  * The methods `fs.read`, `fs.readSync`, `fs.write`, `fs.writeSync`,
    `fs.writeFile` and `fs.writeFileSync` now all accept `TypedArray` and
    `DataView` objects. #22150
  * A new boolean option, `withFileTypes`, can be passed to to `fs.readdir` and
    `fs.readdirSync`. If set to true, the methods return an array of directory
    entries. These are objects that can be used to determine the type of each
    entry and filter them based on that without calling `fs.stat`. #22020
* http2:
  * The `http2` module is no longer experimental. #22466
* os:
  * Added two new methods: `os.getPriority` and `os.setPriority`, allowing to
    manipulate the scheduling priority of processes. #22394
* process:
  * Added `process.allowedNodeEnvironmentFlags`. This object can be used to
    programmatically validate and list flags that are allowed in the
    `NODE_OPTIONS` environment variable. #19335
* src:
  * Deprecated option variables in public C++ API. #22392
  * Refactored options parsing. #22392
* vm:
  * Added `vm.compileFunction`, a method to create new JavaScript functions from
    a source body, with options similar to those of the other `vm` methods. #21571
* Added new collaborators:
  * [lundibundi](https://github.com/lundibundi) - Denys Otrishko

PR-URL: #22716
@targos targos mentioned this pull request Sep 5, 2018
Release proposal: v10.10.0 #22716
Merged
targos added a commit that referenced this pull request Sep 6, 2018
@targos
2018-09-06, Version 10.10.0 (Current)
814a0c0
Notable changes:

* child_process:
  * `TypedArray` and `DataView` values are now accepted as input by
    `execFileSync` and `spawnSync`. #22409
* coverage:
  * Native V8 code coverage information can now be output to disk by setting the
    environment variable `NODE_V8_COVERAGE` to a directory. #22527
* deps:
  * The bundled npm was upgraded to version 6.4.1. #22591
    * Changelogs:
      [6.3.0-next.0](https://github.com/npm/cli/releases/tag/v6.3.0-next.0)
      [6.3.0](https://github.com/npm/cli/releases/tag/v6.3.0)
      [6.4.0](https://github.com/npm/cli/releases/tag/v6.4.0)
      [6.4.1](https://github.com/npm/cli/releases/tag/v6.4.1)
* fs:
  * The methods `fs.read`, `fs.readSync`, `fs.write`, `fs.writeSync`,
    `fs.writeFile` and `fs.writeFileSync` now all accept `TypedArray` and
    `DataView` objects. #22150
  * A new boolean option, `withFileTypes`, can be passed to to `fs.readdir` and
    `fs.readdirSync`. If set to true, the methods return an array of directory
    entries. These are objects that can be used to determine the type of each
    entry and filter them based on that without calling `fs.stat`. #22020
* http2:
  * The `http2` module is no longer experimental. #22466
* os:
  * Added two new methods: `os.getPriority` and `os.setPriority`, allowing to
    manipulate the scheduling priority of processes. #22407
* process:
  * Added `process.allowedNodeEnvironmentFlags`. This object can be used to
    programmatically validate and list flags that are allowed in the
    `NODE_OPTIONS` environment variable. #19335
* src:
  * Deprecated option variables in public C++ API. #22515
  * Refactored options parsing. #22392
* vm:
  * Added `vm.compileFunction`, a method to create new JavaScript functions from
    a source body, with options similar to those of the other `vm` methods. #21571
* Added new collaborators:
  * [lundibundi](https://github.com/lundibundi) - Denys Otrishko

PR-URL: #22716
targos added a commit that referenced this pull request Sep 6, 2018
@targos
2018-09-06, Version 10.10.0 (Current)
cdb3598
Notable changes:

* child_process:
  * `TypedArray` and `DataView` values are now accepted as input by
    `execFileSync` and `spawnSync`. #22409
* coverage:
  * Native V8 code coverage information can now be output to disk by setting the
    environment variable `NODE_V8_COVERAGE` to a directory. #22527
* deps:
  * The bundled npm was upgraded to version 6.4.1. #22591
    * Changelogs:
      [6.3.0-next.0](https://github.com/npm/cli/releases/tag/v6.3.0-next.0)
      [6.3.0](https://github.com/npm/cli/releases/tag/v6.3.0)
      [6.4.0](https://github.com/npm/cli/releases/tag/v6.4.0)
      [6.4.1](https://github.com/npm/cli/releases/tag/v6.4.1)
* fs:
  * The methods `fs.read`, `fs.readSync`, `fs.write`, `fs.writeSync`,
    `fs.writeFile` and `fs.writeFileSync` now all accept `TypedArray` and
    `DataView` objects. #22150
  * A new boolean option, `withFileTypes`, can be passed to to `fs.readdir` and
    `fs.readdirSync`. If set to true, the methods return an array of directory
    entries. These are objects that can be used to determine the type of each
    entry and filter them based on that without calling `fs.stat`. #22020
* http2:
  * The `http2` module is no longer experimental. #22466
* os:
  * Added two new methods: `os.getPriority` and `os.setPriority`, allowing to
    manipulate the scheduling priority of processes. #22407
* process:
  * Added `process.allowedNodeEnvironmentFlags`. This object can be used to
    programmatically validate and list flags that are allowed in the
    `NODE_OPTIONS` environment variable. #19335
* src:
  * Deprecated option variables in public C++ API. #22515
  * Refactored options parsing. #22392
* vm:
  * Added `vm.compileFunction`, a method to create new JavaScript functions from
    a source body, with options similar to those of the other `vm` methods. #21571
* Added new collaborators:
  * [lundibundi](https://github.com/lundibundi) - Denys Otrishko

PR-URL: #22716
targos added a commit that referenced this pull request Sep 6, 2018
@targos
2018-09-06, Version 10.10.0 (Current)
ed976d7
Notable changes:

* child_process:
  * `TypedArray` and `DataView` values are now accepted as input by
    `execFileSync` and `spawnSync`. #22409
* coverage:
  * Native V8 code coverage information can now be output to disk by setting the
    environment variable `NODE_V8_COVERAGE` to a directory. #22527
* deps:
  * The bundled npm was upgraded to version 6.4.1. #22591
    * Changelogs:
      [6.3.0-next.0](https://github.com/npm/cli/releases/tag/v6.3.0-next.0)
      [6.3.0](https://github.com/npm/cli/releases/tag/v6.3.0)
      [6.4.0](https://github.com/npm/cli/releases/tag/v6.4.0)
      [6.4.1](https://github.com/npm/cli/releases/tag/v6.4.1)
* fs:
  * The methods `fs.read`, `fs.readSync`, `fs.write`, `fs.writeSync`,
    `fs.writeFile` and `fs.writeFileSync` now all accept `TypedArray` and
    `DataView` objects. #22150
  * A new boolean option, `withFileTypes`, can be passed to to `fs.readdir` and
    `fs.readdirSync`. If set to true, the methods return an array of directory
    entries. These are objects that can be used to determine the type of each
    entry and filter them based on that without calling `fs.stat`. #22020
* http2:
  * The `http2` module is no longer experimental. #22466
* os:
  * Added two new methods: `os.getPriority` and `os.setPriority`, allowing to
    manipulate the scheduling priority of processes. #22407
* process:
  * Added `process.allowedNodeEnvironmentFlags`. This object can be used to
    programmatically validate and list flags that are allowed in the
    `NODE_OPTIONS` environment variable. #19335
* src:
  * Deprecated option variables in public C++ API. #22515
  * Refactored options parsing. #22392
* vm:
  * Added `vm.compileFunction`, a method to create new JavaScript functions from
    a source body, with options similar to those of the other `vm` methods. #21571
* Added new collaborators:
  * [lundibundi](https://github.com/lundibundi) - Denys Otrishko

PR-URL: #22716
This was referenced Sep 6, 2018
2018-09-06 Version 10.10.0 (Current) @targos beevelop/docker-android-nodejs#236
Closed
2018-09-06 Version 10.10.0 (Current) @targos beevelop/docker-nodejs#221
Closed
@silverwind silverwind added the backport-requested-v8.x label Sep 9, 2018
@silverwind

silverwind commented Sep 9, 2018

Copy link
Copy Markdown
Contributor

If possible, I'd like to see this backported to 8.x.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ajafff
ajafff reviewed Sep 9, 2018
View reviewed changes
Comment thread lib/internal/fs/utils.js
const type = types[i];
if (type === UV_DIRENT_UNKNOWN) {
const name = names[i];
const stats = lazyLoadFs().statSync(pathModule.resolve(path, name));

@ajafff ajafff Sep 9, 2018

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe that was asked before (I didn't read through all comments): why does this use resolve instead of join? At this point name is not expected to be an absolute path.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
ajafff
ajafff reviewed Sep 10, 2018
View reviewed changes
Comment thread lib/internal/fs/utils.js
const type = types[i];
if (type === UV_DIRENT_UNKNOWN) {
const name = names[i];
const stats = lazyLoadFs().statSync(pathModule.resolve(path, name));

@ajafff ajafff Sep 10, 2018

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this use statSync instead of lstatSync? This makes it rather inconsistent because in one case a Dirent may be reported as symbolic link and in case readdir gives type === UV_DIRENT_UNKNOWN symlinks are resolved and the type of the symlinked file is used instead.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@targos targos mentioned this pull request Sep 19, 2018
how to do feature detection #22585
Closed
@coderaiser coderaiser mentioned this pull request Sep 24, 2018
Change Dirent with stat in fs.readdir with withFileTypes #23055
Closed
@outsideris outsideris mentioned this pull request Sep 29, 2018
Translate "Node v10.10.0 (Current)" nodejs/nodejs-ko#757
Merged
@bsiegel bsiegel mentioned this pull request Nov 9, 2018
@types/fs-extra -- Updates needed for Node v10.10+ DefinitelyTyped/DefinitelyTyped#30398
Closed
@silverwind silverwind mentioned this pull request Mar 6, 2019
A proposal to add fs.scandir method to FS module #15699
Closed
@andersk andersk mentioned this pull request Nov 22, 2019
sys: Use readdir withFileTypes option to skip lots of stat syscalls microsoft/TypeScript#35286
Merged
andersk added a commit to andersk/TypeScript that referenced this pull request Nov 22, 2019
@andersk
sys: Use readdir withFileTypes option to skip lots of stat syscalls
bee7ee0
This makes walking large directory trees much more efficient on Node
10.10 or later.

See:
https://lwn.net/Articles/606995/
https://www.python.org/dev/peps/pep-0471/
nodejs/node#22020
https://nodejs.org/en/blog/release/v10.10.0/

Signed-off-by: Anders Kaseorg <[email protected]>
andersk added a commit to andersk/TypeScript that referenced this pull request Jan 13, 2020
@andersk
sys: Use readdir withFileTypes option to skip lots of stat syscalls
5538ffb
This makes walking large directory trees much more efficient on Node
10.10 or later.

See:
https://lwn.net/Articles/606995/
https://www.python.org/dev/peps/pep-0471/
nodejs/node#22020
https://nodejs.org/en/blog/release/v10.10.0/

Signed-off-by: Anders Kaseorg <[email protected]>
amcasey pushed a commit to microsoft/TypeScript that referenced this pull request Jan 15, 2020
@andersk @amcasey
sys: Use readdir withFileTypes option to skip lots of stat syscalls (#…
64704a1
…35286)

This makes walking large directory trees much more efficient on Node
10.10 or later.

See:
https://lwn.net/Articles/606995/
https://www.python.org/dev/peps/pep-0471/
nodejs/node#22020
https://nodejs.org/en/blog/release/v10.10.0/

Signed-off-by: Anders Kaseorg <[email protected]>
Kingwl pushed a commit to Kingwl/TypeScript that referenced this pull request Mar 4, 2020
@andersk @Kingwl
sys: Use readdir withFileTypes option to skip lots of stat syscalls (m…
7e223f2
…icrosoft#35286)

This makes walking large directory trees much more efficient on Node
10.10 or later.

See:
https://lwn.net/Articles/606995/
https://www.python.org/dev/peps/pep-0471/
nodejs/node#22020
https://nodejs.org/en/blog/release/v10.10.0/

Signed-off-by: Anders Kaseorg <[email protected]>
@snyk-bot snyk-bot mentioned this pull request May 3, 2020
[Snyk] Upgrade fast-glob from 2.2.6 to 3.2.2 Frondor/node-autoloader#5
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@addaleax addaleax addaleax approved these changes
@jasnell jasnell jasnell approved these changes
@benjamingr benjamingr benjamingr approved these changes
@BridgeAR BridgeAR BridgeAR approved these changes
+7 more reviewers
@mscdex mscdex mscdex left review comments
@devsnek devsnek devsnek left review comments
@mrmlnc mrmlnc mrmlnc left review comments
@vsemozhetbyt vsemozhetbyt vsemozhetbyt left review comments
@ajafff ajafff ajafff left review comments
@jdalton jdalton jdalton approved these changes
@silverwind silverwind silverwind approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. fs Issues and PRs related to file-system APIs and the fs module. lib / src Issues and PRs involving general changes in the lib/ or src/ directories. semver-minor PRs that contain new features and should be released in the next minor version.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

17 participants

@bengl @nodejs-github-bot @Trott @devsnek @mscdex @ronkorving @silverwind @apapirovski @jdalton @jasnell @addaleax @benjamingr @mrmlnc @BridgeAR @vsemozhetbyt @ajafff @targos
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.