{"action":"created","issue":{"url":"https://api.github.com/repos/jprichardson/node-klaw/issues/13","repository_url":"https://api.github.com/repos/jprichardson/node-klaw","labels_url":"https://api.github.com/repos/jprichardson/node-klaw/issues/13/labels{/name}","comments_url":"https://api.github.com/repos/jprichardson/node-klaw/issues/13/comments","events_url":"https://api.github.com/repos/jprichardson/node-klaw/issues/13/events","html_url":"https://github.com/jprichardson/node-klaw/issues/13","id":192506370,"number":13,"title":"API to stop walking","user":{"login":"targos","id":2352663,"avatar_url":"https://avatars.githubusercontent.com/u/2352663?v=3","gravatar_id":"","url":"https://api.github.com/users/targos","html_url":"https://github.com/targos","followers_url":"https://api.github.com/users/targos/followers","following_url":"https://api.github.com/users/targos/following{/other_user}","gists_url":"https://api.github.com/users/targos/gists{/gist_id}","starred_url":"https://api.github.com/users/targos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/targos/subscriptions","organizations_url":"https://api.github.com/users/targos/orgs","repos_url":"https://api.github.com/users/targos/repos","events_url":"https://api.github.com/users/targos/events{/privacy}","received_events_url":"https://api.github.com/users/targos/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-11-30T08:42:24Z","updated_at":"2016-11-30T15:12:37Z","closed_at":null,"body":"I am using `klaw` to find files but I need to be able to stop walking the directories after a certain limit. I don't think there is currently an official way to do this. Here is my workaround:\r\n```js\r\nfunction getFilesToProcess(directory, maxElements) {\r\n    return new Promise((resolve, reject) => {\r\n        const items = [];\r\n        const walkStream = fs.walk(directory, {queueMethod: 'pop'});\r\n        walkStream.close = function () {\r\n            this.paths = [];\r\n        };\r\n        walkStream\r\n            .on('data', function (item) => {\r\n                if (item.stats.isFile()) {\r\n                    items.push(item.path);\r\n                    if (maxElements > 0 && items.length >= maxElements) {\r\n                        this.close();\r\n                    }\r\n                }\r\n            })\r\n            .on('end', () => resolve(items))\r\n            .on('error', function (err) {\r\n                this.close();\r\n                reject(err);\r\n            });\r\n    });\r\n}\r\n```\r\n\r\nI don't like to have to rely on an implementation detail to achieve this. What do you think about making an official `close` method ?"},"comment":{"url":"https://api.github.com/repos/jprichardson/node-klaw/issues/comments/263897857","html_url":"https://github.com/jprichardson/node-klaw/issues/13#issuecomment-263897857","issue_url":"https://api.github.com/repos/jprichardson/node-klaw/issues/13","id":263897857,"user":{"login":"jprichardson","id":150063,"avatar_url":"https://avatars.githubusercontent.com/u/150063?v=3","gravatar_id":"","url":"https://api.github.com/users/jprichardson","html_url":"https://github.com/jprichardson","followers_url":"https://api.github.com/users/jprichardson/followers","following_url":"https://api.github.com/users/jprichardson/following{/other_user}","gists_url":"https://api.github.com/users/jprichardson/gists{/gist_id}","starred_url":"https://api.github.com/users/jprichardson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jprichardson/subscriptions","organizations_url":"https://api.github.com/users/jprichardson/orgs","repos_url":"https://api.github.com/users/jprichardson/repos","events_url":"https://api.github.com/users/jprichardson/events{/privacy}","received_events_url":"https://api.github.com/users/jprichardson/received_events","type":"User","site_admin":false},"created_at":"2016-11-30T15:12:37Z","updated_at":"2016-11-30T15:12:37Z","body":"Would using `on('readable')` and `read()` and only call `read()` up until `maxElements` solve your problem? See \"Streams 2 & 3 (pull) Example\" in the README for more info."}}
{"actor":{"display_login":"jprichardson"}}