{ "_args": [ [ { "raw": "klaw@^1.0.0", "scope": null, "escapedName": "klaw", "name": "klaw", "rawSpec": "^1.0.0", "spec": ">=1.0.0 <2.0.0", "type": "range" }, "/home/jdaugherty/work/GT2/GT2-Android/node_modules/react-native/node_modules/fs-extra" ] ], "_from": "klaw@>=1.0.0 <2.0.0", "_id": "klaw@1.3.1", "_inCache": true, "_location": "/klaw", "_nodeVersion": "6.5.0", "_npmOperationalInternal": { "host": "packages-18-east.internal.npmjs.com", "tmp": "tmp/klaw-1.3.1.tgz_1477411628636_0.7360875811427832" }, "_npmUser": { "name": "jprichardson", "email": "jprichardson@gmail.com" }, "_npmVersion": "3.10.3", "_phantomChildren": {}, "_requested": { "raw": "klaw@^1.0.0", "scope": null, "escapedName": "klaw", "name": "klaw", "rawSpec": "^1.0.0", "spec": ">=1.0.0 <2.0.0", "type": "range" }, "_requiredBy": [ "/metro/fs-extra", "/react-native/fs-extra" ], "_resolved": "https://registry.npmjs.org/klaw/-/klaw-1.3.1.tgz", "_shasum": "4088433b46b3b1ba259d78785d8e96f73ba02439", "_shrinkwrap": null, "_spec": "klaw@^1.0.0", "_where": "/home/jdaugherty/work/GT2/GT2-Android/node_modules/react-native/node_modules/fs-extra", "author": { "name": "JP Richardson" }, "bugs": { "url": "https://github.com/jprichardson/node-klaw/issues" }, "dependencies": { "graceful-fs": "^4.1.9" }, "description": "File system walker with Readable stream interface.", "devDependencies": { "mkdirp": "^0.5.1", "mock-fs": "^3.8.0", "rimraf": "^2.4.3", "standard": "^8.4.0", "tap-spec": "^4.1.1", "tape": "^4.2.2" }, "directories": {}, "dist": { "shasum": "4088433b46b3b1ba259d78785d8e96f73ba02439", "tarball": "https://registry.npmjs.org/klaw/-/klaw-1.3.1.tgz" }, "gitHead": "7ceea730d54726affeaca62d6e362db0b6881f93", "homepage": "https://github.com/jprichardson/node-klaw#readme", "keywords": [ "walk", "walker", "fs", "fs-extra", "readable", "streams" ], "license": "MIT", "main": "./src/index.js", "maintainers": [ { "name": "jprichardson", "email": "jprichardson@gmail.com" } ], "name": "klaw", "optionalDependencies": { "graceful-fs": "^4.1.9" }, "readme": "Node.js - klaw\n==============\n\nA Node.js file system walker extracted from [fs-extra](https://github.com/jprichardson/node-fs-extra).\n\n[![npm Package](https://img.shields.io/npm/v/klaw.svg?style=flat-square)](https://www.npmjs.org/package/klaw)\n[![build status](https://api.travis-ci.org/jprichardson/node-klaw.svg)](http://travis-ci.org/jprichardson/node-klaw)\n[![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)\n\n\n\"Standard\"\n\nInstall\n-------\n\n npm i --save klaw\n\n\nName\n----\n\n`klaw` is `walk` backwards :p\n\n\nUsage\n-----\n\n### klaw(directory, [options])\n\nReturns a [Readable stream](https://nodejs.org/api/stream.html#stream_class_stream_readable) that iterates\nthrough every file and directory starting with `dir` as the root. Every `read()` or `data` event\nreturns an object with two properties: `path` and `stats`. `path` is the full path of the file and\n`stats` is an instance of [fs.Stats](https://nodejs.org/api/fs.html#fs_class_fs_stats).\n\n- `directory`: The directory to recursively walk. Type `string`.\n- `options`: [Readable stream options](https://nodejs.org/api/stream.html#stream_new_stream_readable_options) and\nthe following:\n - `queueMethod` (`string`, default: `'shift'`): Either `'shift'` or `'pop'`. On `readdir()` array, call either `shift()` or `pop()`.\n - `pathSorter` (`function`, default: `undefined`): Sorting [function for Arrays](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort).\n - `fs` (`object`, default: `require('fs')`): Use this to hook into the `fs` methods or to use [`mock-fs`](https://github.com/tschaub/mock-fs)\n - `filter` (`function`, default: `undefined`): Filtering [function for Arrays](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)\n\n**Streams 1 (push) example:**\n\n```js\nvar klaw = require('klaw')\n\nvar items = [] // files, directories, symlinks, etc\nklaw('/some/dir')\n .on('data', function (item) {\n items.push(item.path)\n })\n .on('end', function () {\n console.dir(items) // => [ ... array of files]\n })\n```\n\n**Streams 2 & 3 (pull) example:**\n\n```js\nvar klaw = require('klaw')\n\nvar items = [] // files, directories, symlinks, etc\nklaw('/some/dir')\n .on('readable', function () {\n var item\n while ((item = this.read())) {\n items.push(item.path)\n }\n })\n .on('end', function () {\n console.dir(items) // => [ ... array of files]\n })\n```\n\nIf you're not sure of the differences on Node.js streams 1, 2, 3 then I'd\nrecommend this resource as a good starting point: https://strongloop.com/strongblog/whats-new-io-js-beta-streams3/.\n\n\n### Error Handling\n\nListen for the `error` event.\n\nExample:\n\n```js\nvar klaw = require('klaw')\nklaw('/some/dir')\n .on('readable', function () {\n var item\n while ((item = this.read())) {\n // do something with the file\n }\n })\n .on('error', function (err, item) {\n console.log(err.message)\n console.log(item.path) // the file the error occurred on\n })\n .on('end', function () {\n console.dir(items) // => [ ... array of files]\n })\n\n```\n\n\n### Aggregation / Filtering / Executing Actions (Through Streams)\n\nOn many occasions you may want to filter files based upon size, extension, etc.\nOr you may want to aggregate stats on certain file types. Or maybe you want to\nperform an action on certain file types.\n\nYou should use the module [`through2`](https://www.npmjs.com/package/through2) to easily\naccomplish this.\n\nInstall `through2`:\n\n npm i --save through2\n\n\n**Example (skipping directories):**\n\n```js\nvar klaw = require('klaw')\nvar through2 = require('through2')\n\nvar excludeDirFilter = through2.obj(function (item, enc, next) {\n if (!item.stats.isDirectory()) this.push(item)\n next()\n})\n\nvar items = [] // files, directories, symlinks, etc\nklaw('/some/dir')\n .pipe(excludeDirFilter)\n .on('data', function (item) {\n items.push(item.path)\n })\n .on('end', function () {\n console.dir(items) // => [ ... array of files without directories]\n })\n\n```\n**Example (ignore hidden directories):**\n```js\nvar klaw = require('klaw')\nvar path = require('path')\n\nvar filterFunc = function(item){\n var basename = path.basename(item)\n return basename === '.' || basename[0] !== '.'\n}\n\nklaw('/some/dir', { filter : filterFunc })\n .on('data', function(item){\n // only items of none hidden folders will reach here\n })\n \n```\n\n**Example (totaling size of PNG files):**\n\n```js\nvar klaw = require('klaw')\nvar path = require('path')\nvar through2 = require('through2')\n\nvar totalPngsInBytes = 0\nvar aggregatePngSize = through2.obj(function (item, enc, next) {\n if (path.extname(item.path) === '.png') {\n totalPngsInBytes += item.stats.size\n }\n this.push(item)\n next()\n})\n\nklaw('/some/dir')\n .pipe(aggregatePngSize)\n .on('data', function (item) {\n items.push(item.path)\n })\n .on('end', function () {\n console.dir(totalPngsInBytes) // => total of all pngs (bytes)\n })\n```\n\n\n**Example (deleting all .tmp files):**\n\n```js\nvar fs = require('fs')\nvar klaw = require('klaw')\nvar through2 = require('through2')\n\nvar deleteAction = through2.obj(function (item, enc, next) {\n this.push(item)\n\n if (path.extname(item.path) === '.tmp') {\n item.deleted = true\n fs.unklink(item.path, next)\n } else {\n item.deleted = false\n next()\n } \n})\n\nvar deletedFiles = []\nklaw('/some/dir')\n .pipe(deleteAction)\n .on('data', function (item) {\n if (!item.deleted) return\n deletedFiles.push(item.path)\n })\n .on('end', function () {\n console.dir(deletedFiles) // => all deleted files\n })\n```\n\nYou can even chain a bunch of these filters and aggregators together. By using\nmultiple pipes.\n\n**Example (using multiple filters / aggregators):**\n\n```js\nklaw('/some/dir')\n .pipe(filterCertainFiles)\n .pipe(deleteSomeOtherFiles)\n .on('end', function () {\n console.log('all done!')\n })\n```\n\n**Example passing (piping) through errors:**\n\nNode.js does not `pipe()` errors. This means that the error on one stream, like\n`klaw` will not pipe through to the next. If you want to do this, do the following:\n\n```js\nvar klaw = require('klaw')\nvar through2 = require('through2')\n\nvar excludeDirFilter = through2.obj(function (item, enc, next) {\n if (!item.stats.isDirectory()) this.push(item)\n next()\n})\n\nvar items = [] // files, directories, symlinks, etc\nklaw('/some/dir')\n .on('error', function (err) { excludeDirFilter.emit('error', err) }) // forward the error on\n .pipe(excludeDirFilter)\n .on('data', function (item) {\n items.push(item.path)\n })\n .on('end', function () {\n console.dir(items) // => [ ... array of files without directories]\n })\n```\n\n\n### Searching Strategy\n\nPass in options for `queueMethod` and `pathSorter` to affect how the file system\nis recursively iterated. See the code for more details, it's less than 50 lines :)\n\n\n\nLicense\n-------\n\nMIT\n\nCopyright (c) 2015 [JP Richardson](https://github.com/jprichardson)\n", "readmeFilename": "README.md", "repository": { "type": "git", "url": "git+https://github.com/jprichardson/node-klaw.git" }, "scripts": { "lint": "standard", "test": "npm run lint && npm run unit", "unit": "tape tests/**/*.js | tap-spec" }, "version": "1.3.1" }