Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

klaw

Package Overview
Dependencies
Maintainers
3
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

klaw - npm Package Compare versions

Comparing version 3.0.0 to 4.0.0

.github/workflows/ci.yml

7

CHANGELOG.md

@@ -0,1 +1,8 @@

4.0.0 / 2021-09-18
------------------
- **BREAKING:** Require Node 14.14.0+ ([#43](https://github.com/jprichardson/node-klaw/pull/43))
- **BREAKING:** Remove graceful-fs dependency; install it manually and pass it as `fs` option if needed ([#43](https://github.com/jprichardson/node-klaw/pull/43))
- Additional documentation examples ([#34](https://github.com/jprichardson/node-klaw/pull/34))
3.0.0 / 2018-08-01

@@ -2,0 +9,0 @@ ------------------

18

package.json
{
"name": "klaw",
"version": "3.0.0",
"version": "4.0.0",
"description": "File system walker with Readable stream interface.",
"main": "./src/index.js",
"scripts": {
"lint": "standard && standard-markdown",
"lint": "standard",
"test": "npm run lint && npm run unit",

@@ -19,6 +19,8 @@ "unit": "tape tests/**/*.js | tap-spec"

"fs",
"fs-extra",
"readable",
"streams"
],
"engines": {
"node": ">=14.14.0"
},
"author": "JP Richardson",

@@ -30,13 +32,7 @@ "license": "MIT",

"homepage": "https://github.com/jprichardson/node-klaw#readme",
"dependencies": {
"graceful-fs": "^4.1.9"
},
"devDependencies": {
"mkdirp": "^0.5.1",
"rimraf": "^2.4.3",
"standard": "^11.0.1",
"standard-markdown": "^4.0.1",
"standard": "^16.0.3",
"tap-spec": "^5.0.0",
"tape": "^4.2.2"
"tape": "^5.3.1"
}
}

@@ -81,2 +81,10 @@ Node.js - klaw

**```for-await-of``` example:**
```js
for await (const file of klaw('/some/dir')) {
console.log(file)
}
```
### Error Handling

@@ -83,0 +91,0 @@

@@ -1,60 +0,68 @@

var assert = require('assert')
var path = require('path')
var Readable = require('stream').Readable
var util = require('util')
const { strictEqual } = require('assert')
const path = require('path')
const fs = require('fs')
const { Readable } = require('stream')
function Walker (dir, options) {
assert.strictEqual(typeof dir, 'string', '`dir` parameter should be of type string. Got type: ' + typeof dir)
var defaultStreamOptions = { objectMode: true }
var defaultOpts = {
queueMethod: 'shift',
pathSorter: undefined,
filter: undefined,
depthLimit: undefined,
preserveSymlinks: false
class Walker extends Readable {
/**
* @param {string} dir
* @param {Object} options
*/
constructor (dir, options) {
strictEqual(typeof dir, 'string', '`dir` parameter should be of type string. Got type: ' + typeof dir)
options = {
queueMethod: 'shift',
pathSorter: undefined,
filter: undefined,
depthLimit: undefined,
preserveSymlinks: false,
...options,
objectMode: true
}
super(options)
this.root = path.resolve(dir)
this.paths = [this.root]
this.options = options
if (options.depthLimit > -1) { this.rootDepth = this.root.split(path.sep).length + 1 }
this.fs = options.fs || fs
}
options = Object.assign(defaultOpts, options, defaultStreamOptions)
Readable.call(this, options)
this.root = path.resolve(dir)
this.paths = [this.root]
this.options = options
if (options.depthLimit > -1) this.rootDepth = this.root.split(path.sep).length + 1
this.fs = options.fs || require('graceful-fs')
}
util.inherits(Walker, Readable)
_read () {
if (this.paths.length === 0) { return this.push(null) }
const pathItem = this.paths[this.options.queueMethod]()
Walker.prototype._read = function () {
if (this.paths.length === 0) return this.push(null)
var self = this
var pathItem = this.paths[this.options.queueMethod]()
const statFunction = this.options.preserveSymlinks ? this.fs.lstat : this.fs.stat
var statFunction = this.options.preserveSymlinks ? self.fs.lstat : self.fs.stat
statFunction(pathItem, (err, stats) => {
const item = { path: pathItem, stats: stats }
if (err) { return this.emit('error', err, item) }
statFunction(pathItem, function (err, stats) {
var item = { path: pathItem, stats: stats }
if (err) return self.emit('error', err, item)
if (!stats.isDirectory() || (this.rootDepth &&
pathItem.split(path.sep).length - this.rootDepth >= this.options.depthLimit)) {
return this.push(item)
}
if (!stats.isDirectory() || (self.rootDepth &&
pathItem.split(path.sep).length - self.rootDepth >= self.options.depthLimit)) {
return self.push(item)
}
this.fs.readdir(pathItem, (err, pathItems) => {
if (err) {
this.push(item)
return this.emit('error', err, item)
}
self.fs.readdir(pathItem, function (err, pathItems) {
if (err) {
self.push(item)
return self.emit('error', err, item)
}
pathItems = pathItems.map(function (part) { return path.join(pathItem, part) })
if (this.options.filter) { pathItems = pathItems.filter(this.options.filter) }
if (this.options.pathSorter) { pathItems.sort(this.options.pathSorter) }
// faster way to do do incremental batch array pushes
this.paths.push.apply(this.paths, pathItems)
pathItems = pathItems.map(function (part) { return path.join(pathItem, part) })
if (self.options.filter) pathItems = pathItems.filter(self.options.filter)
if (self.options.pathSorter) pathItems.sort(self.options.pathSorter)
// faster way to do do incremental batch array pushes
self.paths.push.apply(self.paths, pathItems)
self.push(item)
this.push(item)
})
})
})
}
}
/**
* @param {string} root
* @param {Object} [options]
*/
function walk (root, options) {

@@ -61,0 +69,0 @@ return new Walker(root, options)

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc