{"id":13394900,"url":"https://github.com/dominictarr/stream-spec","last_synced_at":"2025-12-30T00:57:11.640Z","repository":{"id":3804613,"uuid":"4883889","full_name":"dominictarr/stream-spec","owner":"dominictarr","description":"executable specification for Stream (make testing streams easy)","archived":false,"fork":false,"pushed_at":"2015-10-23T21:14:05.000Z","size":170,"stargazers_count":125,"open_issues_count":2,"forks_count":8,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-01-10T15:14:37.308Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dominictarr.png","metadata":{"files":{"readme":"readme.markdown","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-07-04T11:42:14.000Z","updated_at":"2022-07-19T07:43:40.000Z","dependencies_parsed_at":"2022-09-01T08:12:14.712Z","dependency_job_id":null,"html_url":"https://github.com/dominictarr/stream-spec","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dominictarr%2Fstream-spec","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dominictarr%2Fstream-spec/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dominictarr%2Fstream-spec/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dominictarr%2Fstream-spec/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dominictarr","download_url":"https://codeload.github.com/dominictarr/stream-spec/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234152698,"owners_count":18787672,"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-30T17:01:35.558Z","updated_at":"2025-09-25T04:31:32.195Z","avatar_url":"https://github.com/dominictarr.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","Repository","Modules"],"sub_categories":["Streams"],"readme":"# StreamSpec\n\nAutomatic checking of the Stream implementations.\n`stream-spec` instruments your stream to verify that it has correct behaviour.\nAll you need to do to test a stream is to wrap it with `stream-spec`, and then pipe\nsome test data through it.\nit's purpose it to make it easy to test user-land streams have correct behavour.\n\ncorrect stream behaviour [illustrated](https://github.com/dominictarr/stream-spec/blob/master/states.markdown)  \n\ncorrect stream behaviour [explained](https://github.com/dominictarr/stream-spec/blob/master/stream_spec.md)  \n\nstream api design [style](https://github.com/dominictarr/stream-spec/blob/master/api-style.markdown) \n\n## a simple test\n\nusing [stream-tester](https://github.com/dominictarr/stream-tester) \n\n``` js\nvar spec = require('stream-spec')\nvar tester = require('stream-tester')\n\nspec(stream)\n  .through({strict: true})\n  .validateOnExit()\n\ntester.createRandomStream(function () {\n    return 'line ' + Math.random() + '\\n'\n  }, 1000)\n  .pipe(stream)\n  .pipe(tester.createPauseStream())\n\n```\n\nsend 1000 random lines through the stream and check that\nit buffers on pause.\n\n## types of `Stream`\n\n### Writable (but not readable)\n\na `WritableStream` must implement `write`, `end`, `destroy` and emit `'drain'` if it pauses,\nand `'close'` after the stream ends, or is destroyed.\n\nIf the stream is sync (does no io) it probably does not need to pause, so the `write()` should never equal `false`\n\n``` js\nspec(stream)\n  .writable()\n  .drainable()\n  .validateOnExit()\n```\n\n### Readable (but not writable)\n\na `ReadableStream` must emit `'data'`, `'end'`, and implement `destroy`,\nand `'close'` after the stream ends, or is destroyed.\nis strongly recommended to implement `pause` and `resume`\n\nIf the option `{strict: true}` is passed, it means the stream is not allowed to emit\n`'data'` or `'end'` when the stream is paused.\n\nIf the option `{end: false}` is passed, then end may not be emitted.\n\n``` js\nspec(stream)\n  .readable()\n  .pausable({strict: true})) //strict is optional.\n  .validateOnExit()\n```\n\n### Through (sync writable and readable, aka: 'filter')\n\nA `Stream` that is both readable and writable, and where the input is processed and then emitted as output, more or less directly. \nExample, [zlib](http://nodejs.org/api/zlib.html). contrast this with duplex stream.\n\nwhen you call `pause()` on a `ThroughStream`, it should change it into a paused state on the writable side also,\nand `write()===false`. Calling `resume()` should cause `'drain'` to be emitted eventually.\n\nIf the option `{strict: true}` is passed, it means the stream is not allowed to emit\n`'data'` or `'end'` when the stream is paused.\n\n``` js\nspec(stream)\n  .through({strict: true}) //strict is optional. \n  .validateOnExit()\n```\n\n### Duplex\n\nA `Stream` that is both readable and writable, but the streams go off to some other place or thing,\nand are not coupled directly. The readable and writable side of a `DuplexStream` each have their own pause state.\n\nIf the option `{strict: true}` is passed, it means the stream is not allowed to emit\n`'data'` or `'end'` when the stream is paused.\n\n``` js\nspec(stream)\n  .duplex({strict: true})\n  .validateOnExit()\n```\n\n### other options\n\n``` js\nspec(stream, name) //use name as the name of the stream in error messages.\n\nspec(stream, {\n  name: name,   //same as above.\n  strict: true, //'data' nor 'end' may be emitted when paused.\n  error: true,  //this stream *must* error.\n  error: false, //this stream *must not* error.\n                //if neither error: boolean option is passed, the stream *may* error.\n  })\n\n\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdominictarr%2Fstream-spec","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdominictarr%2Fstream-spec","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdominictarr%2Fstream-spec/lists"}