pax_global_header00006660000000000000000000000064141214001430014500gustar00rootroot0000000000000052 comment=04796a92d6a2d8642eb9d208d1d9e03972214ca3 node-klaw-4.0.1/000077500000000000000000000000001412140014300133635ustar00rootroot00000000000000node-klaw-4.0.1/.github/000077500000000000000000000000001412140014300147235ustar00rootroot00000000000000node-klaw-4.0.1/.github/workflows/000077500000000000000000000000001412140014300167605ustar00rootroot00000000000000node-klaw-4.0.1/.github/workflows/ci.yml000066400000000000000000000006521412140014300201010ustar00rootroot00000000000000name: Node.js CI on: push: branches: master pull_request: jobs: test: strategy: matrix: node: [14.x, 16.x] os: [ubuntu-latest, windows-latest] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v2 - name: Use Node.js ${{ matrix.node }} uses: actions/setup-node@v1 with: node-version: ${{ matrix.node }} - run: npm install - run: npm test node-klaw-4.0.1/.gitignore000066400000000000000000000000161412140014300153500ustar00rootroot00000000000000node_modules/ node-klaw-4.0.1/.npmrc000066400000000000000000000000231412140014300144760ustar00rootroot00000000000000package-lock=false node-klaw-4.0.1/CHANGELOG.md000066400000000000000000000044121412140014300151750ustar00rootroot000000000000004.0.1 / 2021-09-18 ------------------ - Don't publish unnecessary files 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 ------------------ - **BREAKING:** Follow symlinks by default (use the new `preserveSymlinks` option to get the old behavior) [#29](https://github.com/jprichardson/node-klaw/pull/29) - **BREAKING:** Drop Node v4 support 2.1.1 / 2017-11-18 ------------------ - Performance optimization [#27](https://github.com/jprichardson/node-klaw/pull/27) 2.1.0 / 2017-08-10 ------------------ ### Added - Added `depthLimit` option to limit how deep to recurse into folders. [#25](https://github.com/jprichardson/node-klaw/pull/25) 2.0.0 / 2017-06-23 ------------------ ### Changed - `graceful-fs` is now a regular dependency, and is always loaded. This should speed up `require` time - Dropped support for Node 0.10 & 0.12 and io.js 1.3.1 / 2016-10-25 ------------------ ### Added - `graceful-fs` added as an `optionalDependencies`. Thanks [ryanzim]! 1.3.0 / 2016-06-09 ------------------ ### Added - `filter` option to pre-filter and not walk directories. 1.2.0 / 2016-04-16 ------------------ - added support for custom `fs` implementation. Useful for https://github.com/tschaub/mock-fs 1.1.3 / 2015-12-23 ------------------ - bugfix: if `readdir` error, got hung up. See: https://github.com/jprichardson/node-klaw/issues/1 1.1.2 / 2015-11-12 ------------------ - assert that param `dir` is a `string` 1.1.1 / 2015-10-25 ------------------ - bug fix, options not being passed 1.1.0 / 2015-10-25 ------------------ - added `queueMethod` and `pathSorter` to `options` to affect searching strategy. 1.0.0 / 2015-10-25 ------------------ - removed unused `filter` param - bugfix: always set `streamOptions` to `objectMode` - simplified, converted from push mode (streams 1) to proper pull mode (streams 3) 0.1.0 / 2015-10-25 ------------------ - initial release [ryanzim]: https://github.com/ryanzim node-klaw-4.0.1/LICENSE000066400000000000000000000020741412140014300143730ustar00rootroot00000000000000(The MIT License) Copyright (c) 2015-2016 JP Richardson Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. node-klaw-4.0.1/README.md000066400000000000000000000170061412140014300146460ustar00rootroot00000000000000Node.js - klaw ============== JavaScript Standard Style A Node.js file system walker extracted from [fs-extra](https://github.com/jprichardson/node-fs-extra). [![npm Package](https://img.shields.io/npm/v/klaw.svg?style=flat-square)](https://www.npmjs.org/package/klaw) [![build status](https://api.travis-ci.org/jprichardson/node-klaw.svg)](http://travis-ci.org/jprichardson/node-klaw) [![windows build status](https://ci.appveyor.com/api/projects/status/github/jprichardson/node-klaw?branch=master&svg=true)](https://ci.appveyor.com/project/jprichardson/node-klaw/branch/master) Install ------- npm i --save klaw If you're using Typescript, we've got [types](https://github.com/DefinitelyTyped/DefinitelyTyped/pull/11492/files): npm i --save-dev @types/klaw Name ---- `klaw` is `walk` backwards :p Sync ---- If you need the same functionality but synchronous, you can use [klaw-sync](https://github.com/manidlou/node-klaw-sync). Usage ----- ### klaw(directory, [options]) Returns a [Readable stream](https://nodejs.org/api/stream.html#stream_class_stream_readable) that iterates through every file and directory starting with `dir` as the root. Every `read()` or `data` event returns an object with two properties: `path` and `stats`. `path` is the full path of the file and `stats` is an instance of [fs.Stats](https://nodejs.org/api/fs.html#fs_class_fs_stats). - `directory`: The directory to recursively walk. Type `string`. - `options`: [Readable stream options](https://nodejs.org/api/stream.html#stream_new_stream_readable_options) and the following: - `queueMethod` (`string`, default: `'shift'`): Either `'shift'` or `'pop'`. On `readdir()` array, call either `shift()` or `pop()`. - `pathSorter` (`function`, default: `undefined`): Sorting [function for Arrays](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort). - `fs` (`object`, default: [`graceful-fs`](https://github.com/isaacs/node-graceful-fs)): Use this to hook into the `fs` methods or to use [`mock-fs`](https://github.com/tschaub/mock-fs) - `filter` (`function`, default: `undefined`): Filtering [function for Arrays](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter) - `depthLimit` (`number`, default: `undefined`): The number of times to recurse before stopping. -1 for unlimited. - `preserveSymlinks` (`boolean`, default: `false`): Whether symlinks should be followed or treated as items themselves. If true, symlinks will be returned as items in their own right. If false, the linked item will be returned and potentially recursed into, in its stead. **Streams 1 (push) example:** ```js const klaw = require('klaw') const items = [] // files, directories, symlinks, etc klaw('/some/dir') .on('data', item => items.push(item.path)) .on('end', () => console.dir(items)) // => [ ... array of files] ``` **Streams 2 & 3 (pull) example:** ```js const klaw = require('klaw') const items = [] // files, directories, symlinks, etc klaw('/some/dir') .on('readable', function () { let item while ((item = this.read())) { items.push(item.path) } }) .on('end', () => console.dir(items)) // => [ ... array of files] ``` **```for-await-of``` example:** ```js for await (const file of klaw('/some/dir')) { console.log(file) } ``` ### Error Handling Listen for the `error` event. Example: ```js const klaw = require('klaw') klaw('/some/dir') .on('readable', function () { let item while ((item = this.read())) { // do something with the file } }) .on('error', (err, item) => { console.log(err.message) console.log(item.path) // the file the error occurred on }) .on('end', () => console.dir(items)) // => [ ... array of files] ``` ### Aggregation / Filtering / Executing Actions (Through Streams) On many occasions you may want to filter files based upon size, extension, etc. Or you may want to aggregate stats on certain file types. Or maybe you want to perform an action on certain file types. You should use the module [`through2`](https://www.npmjs.com/package/through2) to easily accomplish this. Install `through2`: npm i --save through2 **Example (skipping directories):** ```js const klaw = require('klaw') const through2 = require('through2') const excludeDirFilter = through2.obj(function (item, enc, next) { if (!item.stats.isDirectory()) this.push(item) next() }) const items = [] // files, directories, symlinks, etc klaw('/some/dir') .pipe(excludeDirFilter) .on('data', item => items.push(item.path)) .on('end', () => console.dir(items)) // => [ ... array of files without directories] ``` **Example (ignore hidden directories):** ```js const klaw = require('klaw') const path = require('path') const filterFunc = item => { const basename = path.basename(item) return basename === '.' || basename[0] !== '.' } klaw('/some/dir', { filter: filterFunc }) .on('data', item => { // only items of none hidden folders will reach here }) ``` **Example (totaling size of PNG files):** ```js const klaw = require('klaw') const path = require('path') const through2 = require('through2') let totalPngsInBytes = 0 const aggregatePngSize = through2.obj(function (item, enc, next) { if (path.extname(item.path) === '.png') { totalPngsInBytes += item.stats.size } this.push(item) next() }) klaw('/some/dir') .pipe(aggregatePngSize) .on('data', item => items.push(item.path)) .on('end', () => console.dir(totalPngsInBytes)) // => total of all pngs (bytes) ``` **Example (deleting all .tmp files):** ```js const fs = require('fs') const klaw = require('klaw') const through2 = require('through2') const deleteAction = through2.obj(function (item, enc, next) { this.push(item) if (path.extname(item.path) === '.tmp') { item.deleted = true fs.unlink(item.path, next) } else { item.deleted = false next() } }) const deletedFiles = [] klaw('/some/dir') .pipe(deleteAction) .on('data', item => { if (!item.deleted) return deletedFiles.push(item.path) }) .on('end', () => console.dir(deletedFiles)) // => all deleted files ``` You can even chain a bunch of these filters and aggregators together. By using multiple pipes. **Example (using multiple filters / aggregators):** ```js klaw('/some/dir') .pipe(filterCertainFiles) .pipe(deleteSomeOtherFiles) .on('end', () => console.log('all done!')) ``` **Example passing (piping) through errors:** Node.js does not `pipe()` errors. This means that the error on one stream, like `klaw` will not pipe through to the next. If you want to do this, do the following: ```js const klaw = require('klaw') const through2 = require('through2') const excludeDirFilter = through2.obj(function (item, enc, next) { if (!item.stats.isDirectory()) this.push(item) next() }) const items = [] // files, directories, symlinks, etc klaw('/some/dir') .on('error', err => excludeDirFilter.emit('error', err)) // forward the error on .pipe(excludeDirFilter) .on('data', item => items.push(item.path)) .on('end', () => console.dir(items)) // => [ ... array of files without directories] ``` ### Searching Strategy Pass in options for `queueMethod`, `pathSorter`, and `depthLimit` to affect how the file system is recursively iterated. See the code for more details, it's less than 50 lines :) License ------- MIT Copyright (c) 2015 [JP Richardson](https://github.com/jprichardson) node-klaw-4.0.1/package.json000066400000000000000000000015031412140014300156500ustar00rootroot00000000000000{ "name": "klaw", "version": "4.0.1", "description": "File system walker with Readable stream interface.", "main": "./src/index.js", "scripts": { "lint": "standard", "test": "npm run lint && npm run unit", "unit": "tape tests/**/*.js | tap-spec" }, "repository": { "type": "git", "url": "git+https://github.com/jprichardson/node-klaw.git" }, "keywords": [ "walk", "walker", "fs", "readable", "streams" ], "engines": { "node": ">=14.14.0" }, "author": "JP Richardson", "license": "MIT", "files": [ "src/" ], "bugs": { "url": "https://github.com/jprichardson/node-klaw/issues" }, "homepage": "https://github.com/jprichardson/node-klaw#readme", "devDependencies": { "standard": "^16.0.3", "tap-spec": "^5.0.0", "tape": "^5.3.1" } } node-klaw-4.0.1/src/000077500000000000000000000000001412140014300141525ustar00rootroot00000000000000node-klaw-4.0.1/src/index.js000066400000000000000000000040631412140014300156220ustar00rootroot00000000000000const { strictEqual } = require('assert') const path = require('path') const fs = require('fs') const { Readable } = require('stream') 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 } _read () { if (this.paths.length === 0) { return this.push(null) } const pathItem = this.paths[this.options.queueMethod]() const statFunction = this.options.preserveSymlinks ? this.fs.lstat : this.fs.stat statFunction(pathItem, (err, stats) => { const item = { path: pathItem, stats: stats } if (err) { return this.emit('error', err, item) } if (!stats.isDirectory() || (this.rootDepth && pathItem.split(path.sep).length - this.rootDepth >= this.options.depthLimit)) { return this.push(item) } this.fs.readdir(pathItem, (err, pathItems) => { if (err) { this.push(item) return this.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) this.push(item) }) }) } } /** * @param {string} root * @param {Object} [options] */ function walk (root, options) { return new Walker(root, options) } module.exports = walk node-klaw-4.0.1/tests/000077500000000000000000000000001412140014300145255ustar00rootroot00000000000000node-klaw-4.0.1/tests/_test.js000066400000000000000000000014051412140014300162010ustar00rootroot00000000000000const fs = require('fs') const os = require('os') const path = require('path') const tape = require('tape') // for all practical purposes, this is a beforeEach and afterEach function test (desc, testFn) { tape(desc, function (t) { const testDir = path.join(os.tmpdir(), 'klaw-tests') fs.rm(testDir, { recursive: true, force: true }, function (err) { if (err) return t.end(err) fs.mkdir(testDir, function (err) { if (err) return t.end(err) const oldEnd = t.end t.end = function () { fs.rm(testDir, { recursive: true, force: true }, function (err) { err ? oldEnd.apply(t, [err]) : oldEnd.apply(t, arguments) }) } testFn(t, testDir) }) }) }) } module.exports = test node-klaw-4.0.1/tests/fixtures.json000066400000000000000000000001201412140014300172620ustar00rootroot00000000000000[ "a/b/c/d.txt", "a/e.jpg", "h/i/j/k.txt", "h/i/l.txt", "h/i/m.jpg" ] node-klaw-4.0.1/tests/fixtures_links.json000066400000000000000000000002421412140014300204670ustar00rootroot00000000000000{ "a/b.txt": { }, "b": { "type": "file", "target": "./a/b.txt" }, "c": { "type": "dir", "target": "./a" }, "d": { "type": "file", "target": "./broken" } }node-klaw-4.0.1/tests/fixtures_path-sorter.json000066400000000000000000000000301412140014300216120ustar00rootroot00000000000000[ "a", "b", "c" ] node-klaw-4.0.1/tests/walk.test.js000066400000000000000000000033411412140014300170000ustar00rootroot00000000000000const fs = require('fs') const path = require('path') const test = require('./_test') const klaw = require('../') const fixtures = require('./fixtures') test('should work w/ streams 1', function (t, testDir) { fixtures.forEach(function (f) { f = path.join(testDir, f) const dir = path.dirname(f) fs.mkdirSync(dir, { recursive: true }) fs.writeFileSync(f, path.basename(f, path.extname(f))) }) const items = [] klaw(testDir) .on('data', function (item) { items.push(item.path) }) .on('error', t.end) .on('end', function () { items.sort() let expected = ['a', 'a/b', 'a/b/c', 'a/b/c/d.txt', 'a/e.jpg', 'h', 'h/i', 'h/i/j', 'h/i/j/k.txt', 'h/i/l.txt', 'h/i/m.jpg'] expected = expected.map(function (item) { return path.join(path.join(testDir, item)) }) expected.unshift(testDir) t.same(items, expected) t.end() }) }) test('should work w/ streams 2/3', function (t, testDir) { fixtures.forEach(function (f) { f = path.join(testDir, f) const dir = path.dirname(f) fs.mkdirSync(dir, { recursive: true }) fs.writeFileSync(f, path.basename(f, path.extname(f))) }) const items = [] klaw(testDir) .on('readable', function () { let item while ((item = this.read())) { items.push(item.path) } }) .on('error', t.end) .on('end', function () { items.sort() let expected = ['a', 'a/b', 'a/b/c', 'a/b/c/d.txt', 'a/e.jpg', 'h', 'h/i', 'h/i/j', 'h/i/j/k.txt', 'h/i/l.txt', 'h/i/m.jpg'] expected = expected.map(function (item) { return path.join(path.join(testDir, item)) }) expected.unshift(testDir) t.same(items, expected) t.end() }) }) node-klaw-4.0.1/tests/walk_depth-limit.test.js000066400000000000000000000033471412140014300213060ustar00rootroot00000000000000const fs = require('fs') const path = require('path') const test = require('./_test') const klaw = require('../') const fixtures = require('./fixtures.json') test('should honor depthLimit option -1', function (t, testDir) { const expected = ['a', 'a/b', 'a/b/c', 'a/b/c/d.txt', 'a/e.jpg', 'h', 'h/i', 'h/i/j', 'h/i/j/k.txt', 'h/i/l.txt', 'h/i/m.jpg'] run(t, testDir, -1, expected) }) test('should honor depthLimit option 0', function (t, testDir) { const expected = ['a', 'h'] run(t, testDir, 0, expected) }) test('should honor depthLimit option 1', function (t, testDir) { const expected = ['a', 'a/b', 'a/e.jpg', 'h', 'h/i'] run(t, testDir, 1, expected) }) test('should honor depthLimit option 2', function (t, testDir) { const expected = ['a', 'a/b', 'a/b/c', 'a/e.jpg', 'h', 'h/i', 'h/i/j', 'h/i/l.txt', 'h/i/m.jpg'] run(t, testDir, 2, expected) }) test('should honor depthLimit option 3', function (t, testDir) { const expected = ['a', 'a/b', 'a/b/c', 'a/b/c/d.txt', 'a/e.jpg', 'h', 'h/i', 'h/i/j', 'h/i/j/k.txt', 'h/i/l.txt', 'h/i/m.jpg'] run(t, testDir, 3, expected) }) function run (t, testDir, depthLimit, expected) { fixtures.forEach(function (f) { f = path.join(testDir, f) const dir = path.dirname(f) fs.mkdirSync(dir, { recursive: true }) fs.writeFileSync(f, path.basename(f, path.extname(f))) }) const items = [] klaw(testDir, { depthLimit: depthLimit }) .on('data', function (item) { items.push(item.path) }) .on('error', t.end) .on('end', function () { items.sort() expected = expected.map(function (item) { return path.join(path.join(testDir, item)) }) expected.unshift(testDir) t.same(items, expected) t.end() }) } node-klaw-4.0.1/tests/walk_filter.test.js000066400000000000000000000017601412140014300203500ustar00rootroot00000000000000const fs = require('fs') const path = require('path') const test = require('./_test') const klaw = require('../') const fixtures = require('./fixtures') test('should not fire event on filtered items', function (t, testDir) { fixtures.forEach(function (f) { f = path.join(testDir, f) const dir = path.dirname(f) fs.mkdirSync(dir, { recursive: true }) fs.writeFileSync(f, path.basename(f, path.extname(f))) }) const items = [] const filter = function (filepath) { return path.basename(filepath) !== 'a' } klaw(testDir, { filter: filter }) .on('data', function (item) { if (fs.lstatSync(item.path).isFile()) items.push(item.path) }) .on('error', t.end) .on('end', function () { let expected = ['c', 'b', 'a'] expected = expected.map(function (item) { return path.join(testDir, item) }) expected.unshift(testDir) t.ok(items.length < fixtures.length, 'we should see less items due to filter') t.end() }) }) node-klaw-4.0.1/tests/walk_links.test.js000066400000000000000000000035171412140014300202050ustar00rootroot00000000000000const fs = require('fs') const path = require('path') const test = require('./_test') const klaw = require('../') const fixtures = require('./fixtures_links.json') function loadLinkFixtures (testDir) { Object.keys(fixtures).forEach(function (f) { const link = fixtures[f] f = path.join(testDir, f) const dir = path.dirname(f) fs.mkdirSync(dir, { recursive: true }) if (link.target) { const realTarget = path.resolve(testDir, link.target) let missing if (!fs.existsSync(realTarget)) { missing = true fs.writeFileSync(realTarget, '') } fs.symlinkSync(link.target, f, link.type) if (missing) { fs.unlinkSync(realTarget) } } else { fs.writeFileSync(f, path.basename(f, path.extname(f))) } }) } test('should follow links by default', function (t, testDir) { loadLinkFixtures(testDir) const items = [] klaw(testDir) .on('data', function (item) { items.push(item.path) }) .on('error', t.end) .on('end', function () { items.sort() let expected = ['a', 'a/b.txt', 'b', 'c', 'c/b.txt'] expected = expected.map(function (item) { return path.join(path.join(testDir, item)) }) expected.unshift(testDir) t.same(items, expected) t.end() }) }) test('should not follow links if requested', function (t, testDir) { loadLinkFixtures(testDir) const items = [] klaw(testDir, { preserveSymlinks: true }) .on('data', function (item) { items.push(item.path) }) .on('error', t.end) .on('end', function () { items.sort() let expected = ['a', 'a/b.txt', 'b', 'c', 'd'] expected = expected.map(function (item) { return path.join(path.join(testDir, item)) }) expected.unshift(testDir) t.same(items, expected) t.end() }) }) node-klaw-4.0.1/tests/walk_path-sorter.test.js000066400000000000000000000033511412140014300213310ustar00rootroot00000000000000const fs = require('fs') const path = require('path') const test = require('./_test') const klaw = require('../') const fixtures = require('./fixtures_path-sorter.json') const stringCompare = function (a, b) { if (a < b) return -1 else if (a > b) return 1 else return 0 } test('should sort in reverse order [z -> a]', function (t, testDir) { fixtures.forEach(function (f) { f = path.join(testDir, f) const dir = path.dirname(f) fs.mkdirSync(dir, { recursive: true }) fs.writeFileSync(f, path.basename(f, path.extname(f))) }) const items = [] const pathSorter = function (a, b) { return stringCompare(b, a) } klaw(testDir, { pathSorter: pathSorter }) .on('data', function (item) { items.push(item.path) }) .on('error', t.end) .on('end', function () { let expected = ['c', 'b', 'a'] expected = expected.map(function (item) { return path.join(testDir, item) }) expected.unshift(testDir) t.same(items, expected) t.end() }) }) test('should sort in order [a -> z]', function (t, testDir) { fixtures.forEach(function (f) { f = path.join(testDir, f) const dir = path.dirname(f) fs.mkdirSync(dir, { recursive: true }) fs.writeFileSync(f, path.basename(f, path.extname(f))) }) const items = [] const pathSorter = function (a, b) { return stringCompare(a, b) } klaw(testDir, { pathSorter: pathSorter }) .on('data', function (item) { items.push(item.path) }) .on('error', t.end) .on('end', function () { let expected = ['a', 'b', 'c'] expected = expected.map(function (item) { return path.join(testDir, item) }) expected.unshift(testDir) t.same(items, expected) t.end() }) }) node-klaw-4.0.1/tests/walk_read-dir-error.test.js000066400000000000000000000013551412140014300217010ustar00rootroot00000000000000const fs = require('fs') const path = require('path') const test = require('./_test') const klaw = require('../') test('walk directory, if error on readdir, at least end', function (t, testDir) { // simulate directory issue const unreadableDir = path.join(testDir, 'unreadable-dir') fs.mkdirSync(unreadableDir, { recursive: true }) fs.chmodSync(unreadableDir, '0222') // not able to simulate on windows if (process.platform === 'win32') return t.end() t.plan(2) const items = [] klaw(testDir) .on('data', function (item) { items.push(item.path) }) .on('error', function (err) { t.true(err, 'caught error') }) .on('end', function () { t.true(true, 'be sure we end') t.end() }) })