{"id":17472640,"url":"https://github.com/shinnn/read-multiple-files","last_synced_at":"2025-04-09T23:00:23.443Z","repository":{"id":23481071,"uuid":"26846042","full_name":"shinnn/read-multiple-files","owner":"shinnn","description":"Read multiple files Observable way","archived":false,"fork":false,"pushed_at":"2018-12-18T15:22:31.000Z","size":113,"stargazers_count":13,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T00:51:21.868Z","etag":null,"topics":["asynchronous","filesystem","javascript","nodejs","observable","parallel","read"],"latest_commit_sha":null,"homepage":"","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-19T05:27:57.000Z","updated_at":"2019-08-13T15:55:49.000Z","dependencies_parsed_at":"2022-08-22T00:50:56.806Z","dependency_job_id":null,"html_url":"https://github.com/shinnn/read-multiple-files","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shinnn%2Fread-multiple-files","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shinnn%2Fread-multiple-files/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shinnn%2Fread-multiple-files/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shinnn%2Fread-multiple-files/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shinnn","download_url":"https://codeload.github.com/shinnn/read-multiple-files/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248125581,"owners_count":21051768,"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","filesystem","javascript","nodejs","observable","parallel","read"],"created_at":"2024-10-18T17:29:42.877Z","updated_at":"2025-04-09T23:00:23.365Z","avatar_url":"https://github.com/shinnn.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# read-multiple-files\n\n[![npm version](https://img.shields.io/npm/v/read-multiple-files.svg)](https://www.npmjs.com/package/read-multiple-files)\n[![Build Status](https://travis-ci.com/shinnn/read-multiple-files.svg?branch=master)](https://travis-ci.com/shinnn/read-multiple-files)\n[![Coverage Status](https://img.shields.io/coveralls/shinnn/read-multiple-files.svg)](https://coveralls.io/github/shinnn/read-multiple-files)\n\nRead multiple files [Observable](https://github.com/tc39/proposal-observable) way\n\n```javascript\nconst readMultipleFiles = require('read-multiple-files');\n\nreadMultipleFiles(new Set([\n  'one.txt',    // 'a'\n  'another.txt' // 'b'\n])).subscribe({\n  next(result) {\n    if (result.path === 'one.txt') {\n      result.contents; // Buffer.from('a')\n    } else if (result.path === 'another.txt') {\n      result.contents; // Buffer.from('b')\n    }\n  },\n  complete() {\n    console.log('Successfully read all files.');\n  }\n});\n```\n\n## Installation\n\n[Use](https://docs.npmjs.com/cli/install) [npm](https://docs.npmjs.com/about-npm/).\n\n```\nnpm install read-multiple-files\n```\n\n## API\n\n```javascript\nconst readMultipleFiles = require('read-multiple-files');\n```\n\n### readMultipleFiles(*paths* [, *options*])\n\n*paths*: `\u003cArray|Set\u003cstring|Buffer|URL|integer\u003e\u003e` (file paths)  \n*options*: `Object` ([`fs.readFile`](https://nodejs.org/api/fs.html#fs_fs_readfile_path_options_callback) options) or `string` (encoding)  \nReturn: [`Observable`](https://tc39.github.io/proposal-observable/#observable) ([Kevin Smith'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 read files in parallel, successively send each result to its [`Observer`](https://github.com/tc39/proposal-observable#observer) as an `Object`: `{path: \u003cstring|Buffer|URL|integer\u003e, contents: \u003cstring:Buffer\u003e}`\n\n```javascript\nreadMultipleFiles([\n  'foo.txt', // 'Hello'\n  'bar.txt'  // 'World'\n], 'utf8').subscribe({\n  next({path, contents}) {\n    if (path === 'one.txt') {\n      contents; // 'Hello'\n    } else if (path === 'another.txt') {\n      contents; // 'World'\n    }\n  }\n});\n```\n\nThe `Observer` receives an error when it fails to read at least one of the files.\n\n```javascript\nconst readMultipleFiles = require('read-multiple-files');\n\nreadMultipleFiles([\n  'foo.txt', // exists\n  'bar.txt'  // doesn't exist\n]).subscribe({\n  error(err) {\n    err.code; //=\u003e ENOENT\n  },\n  complete() {\n    // `complete` callback will never be called.\n  }\n});\n```\n\n## Related project\n\n* [read-files-promise](https://github.com/shinnn/read-files-promise) — `Promise` interface version\n\n## License\n\n[ISC License](./LICENSE) © 2017 - 2018 Shinnosuke Watanabe\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshinnn%2Fread-multiple-files","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshinnn%2Fread-multiple-files","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshinnn%2Fread-multiple-files/lists"}