Skip to content

the custom readdir-stream class to create an object stream to read a dir. You should implement your readdir, stat functions to use it.

License

Notifications You must be signed in to change notification settings

snowyu/read-dir-stream.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

read-dir-stream npm

Build Status downloads license

the custom readdir-stream class to create an object stream to read a dir. You should implement your readdir, stat functions to use it.

Usage

use it directly:

var fs = require('graceful-fs')
var ReadDirStream = require('read-dir-stream')
var stream = ReadDirStream(dirName, {readdirFn:fs.readdir, statFn: fs.stat})

inherits from:

var fs = require('graceful-fs')
var inherits = require('inherits-ex')
var ReadDirStream = require('read-dir-stream')
function MyReadDirStream() {
  ReadDirStream.apply(this, arguments)
}

inherits(MyReadDirStream, ReadDirStream);

MyReadDirStream.prototype._readdir = fs.readdir;
MyReadDirStream.prototype._stat = fs.stat;

var stream = new MyReadDirStream('.', readdir)

stream.on('data', function(file){
  console.log(file.path)
})

API

constructor(dirName, options)

  • options:
    • cwd (String): optional the current working directory.
    • readdirFn [function(dirName, done)]: the readdir function you must be provided
    • statFn [function(fileName, done)]: the stat function to get the file's stat(must be provided).
    • makeObjFn [function(file)]: the optional makeObj callback function to make a file object.
      • the file object will be passed to makeObjFn function:
        • path: is the file path.
        • stat: is the file stats object if any.
        • cwd: is the dirName of read-dir or cwd if cwd option exist.
      • this file will be ignored if return null.
      • this file object is used as the default if no makeObjFn provided.
    • deepth (number): the recursive deepth of readdir. defaults to 1.

License

MIT

About

the custom readdir-stream class to create an object stream to read a dir. You should implement your readdir, stat functions to use it.

Resources

License

Stars

Watchers

Forks

Packages

No packages published