{"id":13454474,"url":"https://github.com/hughsk/from2","last_synced_at":"2025-05-16T14:07:18.056Z","repository":{"id":13990360,"uuid":"16691428","full_name":"hughsk/from2","owner":"hughsk","description":"Convenience wrapper for ReadableStream, with an API lifted from \"from\" and \"through2\"","archived":false,"fork":false,"pushed_at":"2019-06-11T15:51:29.000Z","size":23,"stargazers_count":132,"open_issues_count":10,"forks_count":21,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-05-12T22:39:48.728Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hughsk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-02-10T10:03:22.000Z","updated_at":"2024-11-01T23:17:33.000Z","dependencies_parsed_at":"2022-07-31T17:48:49.872Z","dependency_job_id":null,"html_url":"https://github.com/hughsk/from2","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hughsk%2Ffrom2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hughsk%2Ffrom2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hughsk%2Ffrom2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hughsk%2Ffrom2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hughsk","download_url":"https://codeload.github.com/hughsk/from2/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254544146,"owners_count":22088807,"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":[],"created_at":"2024-07-31T08:00:54.457Z","updated_at":"2025-05-16T14:07:18.020Z","avatar_url":"https://github.com/hughsk.png","language":"JavaScript","funding_links":[],"categories":["Packages","Repository","JavaScript","Modules","包","Streams","目录"],"sub_categories":["Streams","文件流","流处理","流"],"readme":"# from2 [![Flattr this!](https://api.flattr.com/button/flattr-badge-large.png)](https://flattr.com/submit/auto?user_id=hughskennedy\u0026url=http://github.com/hughsk/from2\u0026title=from2\u0026description=hughsk/from2%20on%20GitHub\u0026language=en_GB\u0026tags=flattr,github,javascript\u0026category=software)[![experimental](http://hughsk.github.io/stability-badges/dist/experimental.svg)](http://github.com/hughsk/stability-badges) #\n\n`from2` is a high-level module for creating readable streams that properly handle backpressure.\n\nConvience wrapper for\n[readable-stream](http://github.com/isaacs/readable-stream)'s `ReadableStream`\nbase class, with an API lifted from\n[from](http://github.com/dominictarr/from) and\n[through2](http://github.com/rvagg/through2).\n\n## Usage ##\n\n[![from2](https://nodei.co/npm/from2.png?mini=true)](https://nodei.co/npm/from2)\n\n### `stream = from2([opts], read)` ###\n\nWhere `opts` are the options to pass on to the `ReadableStream` constructor,\nand `read(size, next)` is called when data is requested from the stream.\n\n* `size` is the recommended amount of data (in bytes) to retrieve.\n* `next(err)` should be called when you're ready to emit more data.\n\nFor example, here's a readable stream that emits the contents of a given\nstring:\n\n``` javascript\nvar from = require('from2')\n\nfunction fromString(string) {\n  return from(function(size, next) {\n    // if there's no more content\n    // left in the string, close the stream.\n    if (string.length \u003c= 0) return next(null, null)\n\n    // Pull in a new chunk of text,\n    // removing it from the string.\n    var chunk = string.slice(0, size)\n    string = string.slice(size)\n\n    // Emit \"chunk\" from the stream.\n    next(null, chunk)\n  })\n}\n\n// pipe \"hello world\" out\n// to stdout.\nfromString('hello world').pipe(process.stdout)\n```\n\n### `stream = from2.obj([opts], read)` ###\n\nShorthand for `from2({ objectMode: true }, read)`.\n\n### `createStream = from2.ctor([opts], read)` ###\n\nIf you're creating similar streams in quick succession you can improve\nperformance by generating a stream **constructor** that you can reuse instead\nof creating one-off streams on each call.\n\nTakes the same options as `from2`, instead returning a constructor which you\ncan use to create new streams.\n\n### See Also\n\n- [from2-array](https://github.com/binocarlos/from2-array) - Create a from2 stream based on an array of source values.\n- [from2-string](https://github.com/yoshuawuyts/from2-string) - Create a stream from a string. Sugary wrapper around from2.\n\n## License ##\n\nMIT. See [LICENSE.md](http://github.com/hughsk/from2/blob/master/LICENSE.md) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhughsk%2Ffrom2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhughsk%2Ffrom2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhughsk%2Ffrom2/lists"}