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

Callback on every file found #16

Closed
math2001 opened this issue Sep 28, 2017 · 4 comments
Closed

Callback on every file found #16

math2001 opened this issue Sep 28, 2017 · 4 comments

Comments

@math2001
Copy link

It'd be nice to have the ability to run a callback on every file, something like this:

fastGlob('sources/*', filename => {
    // do some asynchronous stuff
}).then(filenames => {
    console.log('done')
})
@mrmlnc
Copy link
Owner

mrmlnc commented Sep 29, 2017

Hello, @math2001,

Now you can use transform option. Yeap, it is a synchronous call, but it works right now. See example here.

Can you give an example why you need it?

@math2001
Copy link
Author

It's not absolutely needed, it'd just make things a bit faster I think -> I need to parse every .md file in a directory. That's it.

@mrmlnc
Copy link
Owner

mrmlnc commented Sep 29, 2017

Hm-m, you can use Promises:

const transform = (stat) => new Promise((resolve, reject) => {
    fs.readFile((err, content) => err ? reject(err) : resolve(content));
});

fastGlob('dir/**/*.txt', { transform, onlyFiles: true }).then((files) => {
  // Here files is array of promises to read content of each file
  return Promise.all(files);
}).then((files) => {
  console.log(files); // ['content from dir/a.txt', ...]
});

@mrmlnc mrmlnc closed this as completed Dec 23, 2017
@mrmlnc
Copy link
Owner

mrmlnc commented Dec 23, 2017

Closed as outdated issue. Feel free to reopen if you wanted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants