1.1.0 • Published 8 years ago
dat-readdir-stream v1.1.0
dat-readdir-stream
dat-readdir-stream is a small util to read the file-table of a dat
as a stream, rather than through dat.readdir.
npm i dat-readdir-stream --save
Usage
new ReaddirStream(archive[, opts])archiveHyperdrive archive (object).opts.globDo a glob match over a folder (string).opts.globOptsOptions passed to Minimatch (object).opts.cwdTarget directory path (string), defaults to/.opts.recursiveRead all subfolders and their files as well?opts.maxDepthLimit the depth until which to look into folders.opts.depthFirstUsing a depth-first search instead of the default breadth-first search.- Returns a readable stream in
Object Mode. The payload per entry is an object:entry.locationThe path of the entryentry.statsA Stats object for that path
const ReaddirStream = require('dat-readdir-stream')
var stream = new ReaddirStream(archive, { cwd: '/assets' })
stream.on('data', ({location, stat}) => {
console.log(location) // => '/assets/profile.png', '/assets/styles.css'
console.log(stat.isDirectory()) // => false, false
})
var stream = new ReaddirStream(archive, { recursive: true })
stream.on('data', ({location, stat}) => {
console.log(location) // => '/assets', '/index.html', '/assets/profile.png', '/assets/styles.css'
})
var stream = new ReaddirStream(archive, { recursive: true, depthFirst: true })
stream.on('data', ({location, stat}) => {
console.log(location) // => '/assets', '/assets/profile.png', '/assets/styles.css', '/index.html'
})License
MIT