{"id":17472780,"url":"https://github.com/shinnn/node-read-glob","last_synced_at":"2025-04-09T23:00:19.902Z","repository":{"id":23523547,"uuid":"26889923","full_name":"shinnn/node-read-glob","owner":"shinnn","description":"Search files with glob pattern and read them asynchronously","archived":false,"fork":false,"pushed_at":"2018-02-26T07:04:01.000Z","size":57,"stargazers_count":4,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-04-26T03:22:49.825Z","etag":null,"topics":["asynchronous","glob-pattern","globbing","javascript","nodejs","readfile"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shinnn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-11-20T01:23:29.000Z","updated_at":"2021-06-08T02:38:31.000Z","dependencies_parsed_at":"2022-08-22T00:50:41.362Z","dependency_job_id":null,"html_url":"https://github.com/shinnn/node-read-glob","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shinnn%2Fnode-read-glob","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shinnn%2Fnode-read-glob/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shinnn%2Fnode-read-glob/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shinnn%2Fnode-read-glob/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shinnn","download_url":"https://codeload.github.com/shinnn/node-read-glob/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248008626,"owners_count":21032556,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asynchronous","glob-pattern","globbing","javascript","nodejs","readfile"],"created_at":"2024-10-18T17:36:21.821Z","updated_at":"2025-04-09T23:00:19.729Z","avatar_url":"https://github.com/shinnn.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# read-glob\n\n[![npm version](https://img.shields.io/npm/v/read-glob.svg)](https://www.npmjs.com/package/read-glob)\n[![Build Status](https://travis-ci.org/shinnn/node-read-glob.svg?branch=master)](https://travis-ci.org/shinnn/node-read-glob)\n[![Build status](https://ci.appveyor.com/api/projects/status/9cf2k7pkog7ax2fs/branch/master?svg=true)](https://ci.appveyor.com/project/ShinnosukeWatanabe/node-read-glob/branch/master)\n[![Coverage Status](https://img.shields.io/coveralls/shinnn/node-read-glob.svg)](https://coveralls.io/github/shinnn/node-read-glob)\n\nSearch files with glob pattern and read them, [Observable](https://github.com/tc39/proposal-observable) way\n\n```javascript\nconst readGlob = require('read-glob');\n\nreadGlob('src/*.js').subscribe({\n  start() {\n    console.log('Glob started.');\n  },\n  next(result) {\n    result.cwd; //=\u003e '/Users/shinnn/exmaple'\n    result.path; //=\u003e 'src/a.js'\n    result.contents; //=\u003e \u003cBuffer ... \u003e\n  },\n  complete() {\n    console.log('Glob completed.');\n  }\n});\n```\n\n## Installation\n\n[Use](https://docs.npmjs.com/cli/install) [npm](https://docs.npmjs.com/getting-started/what-is-npm).\n\n```\nnpm install read-glob\n```\n\n## API\n\n```javascript\nconst readGlob = require('read-glob');\n```\n\n### readGlob(*pattern* [, *options*])\n\n*pattern*: `string` (glob pattern)  \n*options*: `Object` ([`node-glob`] and [`fs.readFile`] options) or `string` (encoding)  \nReturn: [`Observable`](https://github.com/tc39/proposal-observable#observable) ([zenparsing's implementation](https://github.com/zenparsing/zen-observable))\n\nWhen the `Observable` is [subscribe](https://tc39.github.io/proposal-observable/#observable-prototype-subscribe)d, it starts to search files matching the given glob pattern, read their contents and successively send results to its [`Observer`](https://github.com/tc39/proposal-observable#observer).\n\n#### Results\n\nEach result is the same `Object` as [`glob-observable`'s](https://github.com/shinnn/glob-observable#match-result) with the additional `contents` property, a `Buffer` or `string` of the matched file contents.\n\n`contents` is a `string` when the `encoding` option is specified, otherwise it's a `Buffer`.\n\n```javascript\nreadGlob('hi.txt').subscribe(result =\u003e {\n  result.contents; //=\u003e \u003cBuffer 48 69\u003e\n});\n\nreadGlob('hi.txt', 'utf8').subscribe(result =\u003e {\n  result.contents; //=\u003e 'Hi'\n});\n\nreadGlob('hi.txt', 'base64').subscribe(result =\u003e {\n  result.contents; //=\u003e 'SGk='\n});\n```\n\n#### options\n\nThe option object will be directly passed to [`node-glob`] and [`fs.readFile`], or the encoding string sets the encoding of `fs.readFile`.\n\nUnlike the original node-glob API,\n\n* `silent` and `strict` options are `true` by default.\n* `nodir` and `mark` options are not supported as it ignores directories by default.\n\n```javascript\nconst readGlob = require('read-glob');\n\n// ./directory/.dot.txt: 'Hello'\n\nreadGlob('*.txt', {\n  cwd: 'directory',\n  dot: true\n}).subscribe(({contents}) =\u003e {\n  contents.toString(); //=\u003e 'Hello'\n});\n```\n\n## Related project\n\n* [read-glob-promise](https://github.com/shinnn/read-glob-promise) ([Promise](https://promisesaplus.com/) version)\n\n## License\n\n[ISC License](./LICENSE) © 2017 - 2018 Shinnosuke Watanabe\n\n[`fs.readFile`]: https://nodejs.org/api/fs.html#fs_fs_readfile_path_options_callback\n[`node-glob`]: https://github.com/isaacs/node-glob#options\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshinnn%2Fnode-read-glob","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshinnn%2Fnode-read-glob","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshinnn%2Fnode-read-glob/lists"}