{"name":"read-stream","version":"2.0.2","description":"Base class for readable streams","keywords":[],"author":{"name":"Raynos","email":"raynos2@gmail.com"},"repository":{"type":"git","url":"git://github.com/Raynos/read-stream.git"},"main":"index","homepage":"https://github.com/Raynos/read-stream","contributors":[{"name":"Jake Verbaten"}],"bugs":{"url":"https://github.com/Raynos/read-stream/issues","email":"raynos2@gmail.com"},"dependencies":{"readable-stream":"git://github.com/Raynos/readable-stream#read-stream","process":"~0.5.1"},"devDependencies":{"testem":"~0.2.70","browserify":"~1.18.0","tape":"~0.2.2"},"licenses":[{"type":"MIT","url":"http://github.com/Raynos/read-stream/raw/master/LICENSE"}],"scripts":{"build":"browserify test/index.js -o test/static/bundle.js","test":"testem ci"},"testling":{"files":"test/index.js","browsers":{"ie":["8","9","10"],"firefox":["16","17","nightly"],"chrome":["22","23","canary"],"opera":["12","next"],"safari":["5.1"]}},"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 `push(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.push(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 `push(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        push(err || 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","readmeFilename":"README.md","_id":"read-stream@2.0.2","dist":{"shasum":"eea31dbb2deb92842c8f3e898060df341d31884f","tarball":"http://registry-npm.ywwl.com/read-stream/download/read-stream-2.0.2.tgz","integrity":"sha512-VTEGzHTwDcTIFEvh+5bWeFd6C1aStbVHUZ7UHhcqfzq7R4q8r0x4CLdJDzL0d+A8u0yGG6cXy3f6bTVsDmW5Jg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIC7KRVtdksA+JgnbF/BaQnj2Ig2LAXSoHJM8ZZ+8raanAiEAqENSUFXDBGBoymQTbPfDo3gTl3o3JKjbyx+u1cndBLU="}],"size":8047,"noattachment":false,"key":"/read-stream/-/read-stream-2.0.2.tgz"},"_from":".","_npmVersion":"1.2.3","_npmUser":{"name":"raynos","email":"raynos2@gmail.com"},"maintainers":[{"name":"raynos","email":"raynos2@gmail.com"}],"directories":{},"publish_time":1361438564177,"_cnpm_publish_time":1361438564177,"dist-tags":{"latest":"2.1.1"}}