{"bugs":{"url":"https://github.com/Raynos/read-stream/issues","email":"raynos2@gmail.com"},"dist":{"shasum":"177d60e9fe484c93ae76e5ac0098552251242c81","tarball":"https://registry.npmjs.org/read-stream/-/read-stream-2.1.1.tgz","integrity":"sha512-UcZnoo+AEM+ipqwOQ4JLxkIDYyWvOT3hvcal/fSL3VFFUKeHoHgC89gltJtekAejj+ji7dTe0TVb5mpj8/kt0g==","signatures":[{"sig":"MEQCIG9D5296lByFNMLjHfHnDHOdkVxYu01w35G3zioELXIwAiBmtEKbVUUecGwdYGxNFk6CBw62GjaxNW6re8FREwqaNw==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index","name":"read-stream","_from":".","author":{"name":"Raynos","email":"raynos2@gmail.com"},"readme":"# read-stream\n\n[![build status][1]][2] [![dependency status][3]][4]\n\n[![browser support][5]][6]\n\nBase class for readable streams\n\nThis should be used for object streams only.\n\n## Example push model\n\nA push source can be turned into a `Readable Stream` by creating\nan instance of the source and creating a stream.\n\nWhen the `onread` listener of the stream get's called it's time\nto start consuming data from the source. (like `source.resume()`\nor `source.readStart()`). Note that `onread` may get called\nmultiple times even when the source your wrapping in a stream\nhas already started. So `resume()` / `readStart()` should be handle\nbeing called multiple times.\n\nWhen you get actual data out of the raw source you should `push(data)`\ninto the stream. `push` returns a boolean whether or not the\nstream's buffer is full. If it's full you need to stop reading\nfrom the source (like `source.pause()` or `source.readStop()`).\n\n`push()` returns false when the internal buffer matches the\n`highWaterMark`. This defaults to `100` for `ReadStream`. You can\nconfigure it using\n\n```js\nvar stream = ReadStream({\n    highWaterMark: 20\n}, function onread() { ... })\n```\n\nIf the source emits some kind of `EOF` you should call `push(null)`\nand if the source emits some kind of error you can just `emit(\"error\", err)`\n\n```js\nvar ReadStream = require(\"read-stream\")\n\nvar socket = connect(...)\nvar stream = ReadStream(function onread(push, cb) {\n    socket.readStart()\n})\n\nsocket.ondata = function (chunk) {\n    var needsMore = stream.push(chunk)\n\n    if (!needsMore) {\n        socket.readStop()\n    }\n}\n\nsocket.onend = function () {\n    stream.push(null)\n}\n\nsocket.onerror = function (err) {\n    stream.emit(\"error\", err)\n}\n\nstream.pipe(process.stdout)\n```\n\n## Example pull model\n\nA pull source can be made into a `Readable Stream` in a way easier\nfashion. Create an instance of the raw pull source and create a\nstream.\n\nWhen the `onread` listener of the stream is called you should\npull data out of the underlying source and `push()` it into\nthe stream. If you `push()` data into the stream and the underlying\nbuffer is below the `lowWaterMark` then `onread` will be called\nagain immediately. The `lowWaterMark` can be configured and defaults\nto 0\n\n```js\nvar stream = ReadStream({\n    lowWaterMark: 5\n}, function onread() {})\n```\n\nWhen a user calls `read()` on the stream and the internal buffer\nis below the `highWaterMark` after read removes an item then\n`onread` will be called again.\n\nNote that it the underlying source returns an `err` or returns\nan `EOF` you should `emit(\"error\", err)` and `push(null)` respectively.\n\n```js\nvar ReadStream = require(\"read-stream\")\n\nvar source = db.cursor(...)\nvar stream = ReadStream(function onread(push, cb) {\n    cursor.nextObject(function (err, item) {\n        if (err) {\n            return stream.emit(\"error\", err)\n        }\n\n        push(item || null)\n    })\n})\n\nstream.pipe(process.stdout)\n```\n\n## Example array\n\nIf you want to turn an array into a stream for testing / example\npurposes then use the `array` function.\n\n```js\nvar fromArray = require(\"read-stream/array\")\nvar stream = fromArray([\"one\", \"two\"])\n\nstream.pipe(process.stdout)\n```\n\n## Example callback\n\nIf you want to turn a callback operation into a stream then\nyou can use the `callback` function.\n\n```js\nvar callback = require(\"read-stream/callback\")\n\nvar stream = callback(function (cb) {\n    fs.readFile(someUri, cb)\n})\n\nstream.pipe(process.stdout)\n```\n\n## Installation\n\n`npm install read-stream`\n\n## Contributors\n\n - Raynos\n\n## MIT Licenced\n\n  [1]: https://secure.travis-ci.org/Raynos/read-stream.png\n  [2]: http://travis-ci.org/Raynos/read-stream\n  [3]: http://david-dm.org/Raynos/read-stream.png\n  [4]: http://david-dm.org/Raynos/read-stream\n  [5]: http://ci.testling.com/Raynos/read-stream.png\n  [6]: http://ci.testling.com/Raynos/read-stream\n","scripts":{"test":"testem ci","build":"browserify test/index.js -o test/static/bundle.js"},"_npmUser":{"name":"raynos","email":"raynos2@gmail.com"},"homepage":"https://github.com/Raynos/read-stream","keywords":[],"licenses":[{"url":"http://github.com/Raynos/read-stream/raw/master/LICENSE","type":"MIT"}],"testling":{"files":"test/index.js","browsers":{"ie":["8","9","10"],"ipad":["6.0"],"opera":["12","next"],"chrome":["22","23","canary"],"iphone":["6.0"],"safari":["5.1","6.0"],"firefox":["16","17","nightly"]}},"repository":{"url":"git://github.com/Raynos/read-stream.git","type":"git"},"_npmVersion":"1.2.3","description":"Base class for readable streams","maintainers":[{"name":"raynos","email":"raynos2@gmail.com"}],"contributors":[{"name":"Jake Verbaten"}],"dependencies":{"process":"~0.5.1","readable-stream":"git://github.com/Raynos/readable-stream#read-stream"},"readmeFilename":"README.md","devDependencies":{"tape":"~0.2.2","testem":"~0.2.70","browserify":"~1.18.0"},"_id":"read-stream@2.1.1","version":"2.1.1"}