GithubHelp home page GithubHelp logo

js-devtools / readdir-enhanced Goto Github PK

View Code? Open in Web Editor NEW
85.0 85.0 8.0 592 KB

fs.readdir() with filter, recursion, absolute paths, promises, streams, and more!

Home Page: https://jstools.dev/readdir-enhanced/

License: MIT License

JavaScript 68.26% TypeScript 31.74%
async directory eventemitter filesystem filter javascript ls nodejs readdir recursion stream

readdir-enhanced's People

Contributors

greenkeeperio-bot avatar jamesmessinger avatar mrmlnc avatar papb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

readdir-enhanced's Issues

No files are streamed when you omit the 'data' handler.

I want to build a stream and only listen to files. I'm building it like so:

const files = readdirEnhanced.readdirStreamStat('/tmp/test')

files.on('file', (file) => console.log(file))
files.on('end', () => console.log('end'))

If I run the above code, no files pass through the stream. If I add a data listener (even an empty function), things start moving:

const files = readdirEnhanced.readdirStreamStat('/tmp/test')

files.on('data', () => {
  // no-op
})

files.on('file', (file) => console.log(file))
files.on('end', () => console.log('end'))

Is this intended behaviour? If so, I'm happy to update the documentation a bit to make it clearer why the data handler is needed.

Cheers

readdir.sync.stat should have option to silently fail

I use the following under Windows

const readdir = require('readdir-enhanced')
const result = readdir.sync.stat('C:/')

Under my system this fails because some files are protected (for instance C:\pagefile.sys). Should there be an option to either skip those errors and return the rest of the file stats, or to return the other files as part of the exception payload?

Question about reading directories

Hello, @BigstickCarpet,

Firstly, very thanks you for this package. This package works faster analogues and covers all my needs. ๐ŸŒฎ

Do you not think about how to prevent the reading of the directory, if it has been filtered? I'm not mean filter of results, I talk about skip the contents of the directory, if it has been filtered.

For example,

filter

function filter(stat) {
  console.log('stat: ', stat.path);
  if (stat.isDirectory() && stat.path === 'a') {
    console.log('Hello from the "a/" directory!');
    return false;
  }
  return true;
}

current behaviour

stat:  a
Hello from the "a/" directory!
stat:  a.txt
stat:  a\b                  // <--- but "a" is filtered
stat:  a\b\b.no-txt    // <--- but "a" is filtered
stat:  a\b\c               // <--- but "a" is filtered
stat:  a\b\c\d           // <--- but "a" is filtered
stat:  a\b\c\d\e.txt   // <--- but "a" is filtered

expected behaviour

stat:  a
Hello from the "a/" directory!
stat:  a.txt

I ask because this may severely degrade performance on very large projects.

{filter: '*.txt'} returns empty files array

when i use filter: '*txt in my code it always return empty array
readdir(path1, { basePath: path1, filter: "*.txt", deep: true}, function(err, files) {

if i remove the filter i will show all the files in the directory including the subdirectories

Maximum call stack size exceeded with filters

Hello,

And it's me again :)

We have a small problem. When working with large nested directory, we often apply the filter. For example, built-in filter by patterns:

const re = require('readdir-enhanced');

let files = null;

try {
    files = re.sync('./node_modules', {
        deep: true,
        filter: '**/test-*'
    });
} catch (error) {
    console.log('MEMORY: ' + (process.memoryUsage().heapUsed / 1e6) + ' MB');

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

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

In the example above, I call the reading of the directory that contains 20320 entries:

$ npm i jest ava babel-core standard eslint typescript tslint monaco xterm readdir-enhanced

After running the script we get the following:

MEMORY: 9.37484 MB

node_modules/readdir-enhanced/lib/call.js:51
      throw err;
      ^

RangeError: Maximum call stack size exceeded
    at Object.fs.lstatSync (fs.js:839:18)
    at exports.lstat (node_modules/readdir-enhanced/lib/sync/fs.js:58:20)
    at Object.safeCall [as safe] (node_modules/readdir-enhanced/lib/call.js:24:8)
    at stat (node_modules/readdir-enhanced/lib/stat.js:19:8)
    at DirectoryReader.processItem (node_modules/readdir-enhanced/lib/directory-reader.js:171:5)
    at node_modules/readdir-enhanced/lib/sync/for-each.js:14:5
    at Array.forEach (native)
    at Object.syncForEach [as forEach] (node_modules/readdir-enhanced/lib/sync/for-each.js:13:9)
    at node_modules/readdir-enhanced/lib/directory-reader.js:80:16
    at onceWrapper (node_modules/readdir-enhanced/lib/call.js:45:17)

If I remove any filter (pattern, function), everything works fine.

Add npm install instructions

Should add something that says

Installation

npm install --save readdir-enhanced

This would help identifying the npm repository as genuine.

Knowing when readdir.stream is finished?

Is there a way with readdir.stream() to know when it is finished? I couldn't see any appropriate event for this or anything in the docs.

Note, I did try .on('finish', function () { }), but this did not get called.

Ability to use depth in the custom deep function

If we use deep option as custom function we cannot control depth. May be we must provide number of depth to function arguments?

For example:

const options = {
	deep: (entry: IReaddirEntry, depth: number) => ...
};

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.