fs-readdir

2019-04-13 admin

fs-readdir是什么

什么是fs-readdir,fs.readdir done right! Support sync, async and stream API, recursiveness and filters/globs.

fs-readdir使用教程帮助文档

npm mit license build status coverage status deps status

fs.readdir done right! Support sync, async and stream API, recursiveness and filters.

Install, Test & Benchmark

npm i --save fs-readdir
node benchmark

Usage

For more use-cases see the tests

var fsReaddir = require('fs-readdir');
var through2 = require('through2');

// callback api
fsReaddir('../gitclone-cli', function _cb(err, filepaths) {
  // as usual
  console.log('callback err:', err)
  console.log('callback res:', filepaths)
});

// as stream
var stream = fsReaddir('../gitclone-cli')
.on('error', function(err) {
  console.log('error:', err);
})
.on('finish', function(obj) {
  console.log('finish:', obj);
})
.on('data', function(obj) {
  console.log('data:', obj);
})
.on('folder', function(folder) {
  console.log('folder:', folder);
})
.on('file', function(file) {
  console.log('file:', file);
})
.pipe(through2.obj(function(objArray, enc, next) {
  objArray = objArray.map(function(fp) {
    return path.basename(fp);
  })
  console.log('pipe1:', objArray);
  this.push(objArray)
  next();
})).pipe(through2.obj(function(modified, enc, next) {
  console.log('pipe2:', modified);
  this.push(modified)
  next();
}))

Benchmark

charlike@node:~/dev/fs-readdir$ node benchmark
#1: simple.js 
  fs-readdir-builtin-emitter.js x 46,994 ops/sec ±13.86% (48 runs sampled)
  fs-readdir-callback-api.js x 54,294 ops/sec ±6.17% (59 runs sampled)
  fs-readdir-dual-emitter.js x 19,177 ops/sec ±8.48% (51 runs sampled)
  fs-readdir-eventemitter2.js x 75,735 ops/sec ±36.43% (51 runs sampled)
  fs-readdir-stream-api.js x 18,181 ops/sec ±7.42% (65 runs sampled)
  glob-stream.js x 505 ops/sec ±5.54% (72 runs sampled)
  readdirp-callback-api.js x 17,271 ops/sec ±19.92% (39 runs sampled)
  readdirp-stream-api.js x 3,458 ops/sec ±6.40% (56 runs sampled)
  recursive-readdir.js x 36,467 ops/sec ±8.17% (51 runs sampled)

  fastest is fs-readdir-callback-api.js
charlike@node:~/dev/fs-readdir$ node benchmark
#1: simple.js 
  fs-readdir-builtin-emitter.js x 61,303 ops/sec ±13.48% (53 runs sampled)
  fs-readdir-callback-api.js x 104,814 ops/sec ±8.41% (59 runs sampled)
  fs-readdir-dual-emitter.js x 29,277 ops/sec ±15.30% (50 runs sampled)
  fs-readdir-eventemitter2.js x 43,540 ops/sec ±31.92% (55 runs sampled)
  fs-readdir-stream-api.js x 37,138 ops/sec ±8.37% (60 runs sampled)
  glob-stream.js x 432 ops/sec ±27.02% (52 runs sampled)
  readdirp-callback-api.js x 6,506 ops/sec ±7.89% (57 runs sampled)
  readdirp-stream-api.js x 4,579 ops/sec ±59.87% (4 runs sampled)
  recursive-readdir.js x 32,405 ops/sec ±12.46% (25 runs sampled)

  fastest is fs-readdir-callback-api.js
charlike@node:~/dev/fs-readdir$ node benchmark
#1: simple.js 
  fs-readdir-builtin-emitter.js x 35,380 ops/sec ±16.06% (46 runs sampled)
  fs-readdir-callback-api.js x 55,063 ops/sec ±17.40% (45 runs sampled)
  fs-readdir-dual-emitter.js x 22,400 ops/sec ±7.50% (71 runs sampled)
  fs-readdir-eventemitter2.js x 34,917 ops/sec ±9.39% (49 runs sampled)
  fs-readdir-stream-api.js x 66,513 ops/sec ±24.33% (42 runs sampled)
  glob-stream.js x 500 ops/sec ±7.51% (72 runs sampled)
  readdirp-callback-api.js x 11,054 ops/sec ±10.86% (47 runs sampled)
  readdirp-stream-api.js x 2,277 ops/sec ±5.37% (68 runs sampled)
  recursive-readdir.js x 12,956 ops/sec ±55.23% (50 runs sampled)

  fastest is fs-readdir-callback-api.js
charlike@node:~/dev/fs-readdir$ node benchmark
#1: simple.js 
  fs-readdir-builtin-emitter.js x 71,767 ops/sec ±12.90% (55 runs sampled)
  fs-readdir-callback-api.js x 55,266 ops/sec ±8.16% (60 runs sampled)
  fs-readdir-dual-emitter.js x 19,824 ops/sec ±9.25% (49 runs sampled)
  fs-readdir-eventemitter2.js x 40,454 ops/sec ±30.43% (54 runs sampled)
  fs-readdir-stream-api.js x 33,384 ops/sec ±8.23% (65 runs sampled)
  glob-stream.js x 584 ops/sec ±5.70% (70 runs sampled)
  readdirp-callback-api.js x 17,492 ops/sec ±20.65% (42 runs sampled)
  readdirp-stream-api.js x 2,375 ops/sec ±6.73% (46 runs sampled)
  recursive-readdir.js x 47,471 ops/sec ±35.03% (53 runs sampled)

  fastest is fs-readdir-callback-api.js

Author

Charlike Mike Reagent

License MIT license

Copyright © 2014-2015 Charlike Mike Reagent, contributors. Released under the MIT license.


Powered and automated by kdf, February 13, 2015

你可能感兴趣的文章:

本站文章除注明转载外,均为本站原创或编译。欢迎任何形式的转载,但请务必注明出处。

转载请注明:文章转载自 JavaScript中文网 [https://www.javascriptcn.com]

本文地址:https://www.javascriptcn.com/read-61668.html

文章标题:fs-readdir

回到顶部