Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Implementing "withFileTypes" option for fs.readdir method #287

Merged
merged 1 commit into from
Jan 7, 2020

Conversation

mrmlnc
Copy link
Contributor

@mrmlnc mrmlnc commented Jan 3, 2020

Hi, I'm the maintainer of the fast-glob package.

In my package, I try to use all possible ways to optimize the work with the file system. One of these ways is a withFileTypes option in the fs.readdir method. Unfortunately, this package does not support this option. So, this pull request implements support for this option.

This is a possible solution for the following issues:

My solution uses an internal implementation of the getDirents method from FSReqWrap, because I don't know how to replace callback. I will accept any suggestions if it really needs to be done.

I checked that my changes are working by the following script:

const mock = require('.');
const fg = require('fast-glob');

mock({
    first: 'content',
    second: {},
    third: {
        nested: {
            file: 'content'
        }
    }
});

const entries = fg.sync('**/*', { onlyFiles: false, objectMode: true });

console.dir(entries, { colors: true });

[ { dirent: Dirent { name: 'first', [Symbol(type)]: 1 },
    name: 'first',
    path: 'first' },
  { dirent: Dirent { name: 'second', [Symbol(type)]: 2 },
    name: 'second',
    path: 'second' },
  { dirent: Dirent { name: 'third', [Symbol(type)]: 2 },
    name: 'third',
    path: 'third' },
  { dirent: Dirent { name: 'nested', [Symbol(type)]: 2 },
    name: 'nested',
    path: 'third/nested' },
  { dirent: Dirent { name: 'file', [Symbol(type)]: 1 },
    name: 'file',
    path: 'third/nested/file' } ]

lib/binding.js Show resolved Hide resolved
@3cp
Copy link
Collaborator

3cp commented Jan 4, 2020

LGTM. cc @tschaub

@tschaub tschaub merged commit 60cca44 into tschaub:master Jan 7, 2020
@tschaub
Copy link
Owner

tschaub commented Jan 7, 2020

Looks great. Thanks for the contribution @mrmlnc!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants