pax_global_header00006660000000000000000000000064121455264210014514gustar00rootroot0000000000000052 comment=2a0225ad78643a88af86ba70e44977a4f5d681fa resumer-0.0.0/000077500000000000000000000000001214552642100131735ustar00rootroot00000000000000resumer-0.0.0/.travis.yml000066400000000000000000000000601214552642100153000ustar00rootroot00000000000000language: node_js node_js: - "0.8" - "0.10" resumer-0.0.0/LICENSE000066400000000000000000000020611214552642100141770ustar00rootroot00000000000000This software is released under the MIT license: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. resumer-0.0.0/example/000077500000000000000000000000001214552642100146265ustar00rootroot00000000000000resumer-0.0.0/example/resume.js000066400000000000000000000002611214552642100164630ustar00rootroot00000000000000var resumer = require('../'); createStream().pipe(process.stdout); function createStream () { var stream = resumer(); stream.queue('beep boop\n'); return stream; } resumer-0.0.0/index.js000066400000000000000000000011511214552642100146360ustar00rootroot00000000000000var through = require('through'); var nextTick = typeof setImmediate !== 'undefined' ? setImmediate : process.nextTick ; module.exports = function (write, end) { var tr = through(write, end); tr.pause(); var resume = tr.resume; var pause = tr.pause; var paused = false; tr.pause = function () { paused = true; return pause.apply(this, arguments); }; tr.resume = function () { paused = false; return resume.apply(this, arguments); }; nextTick(function () { if (!paused) tr.resume(); }); return tr; }; resumer-0.0.0/package.json000066400000000000000000000020721214552642100154620ustar00rootroot00000000000000{ "name": "resumer", "version": "0.0.0", "description": "a through stream that starts paused and resumes on the next tick", "main": "index.js", "dependencies": { "through": "~2.3.4" }, "devDependencies": { "tap": "~0.4.0", "tape": "~1.0.2", "concat-stream": "~0.1.1" }, "scripts": { "test": "tap test/*.js" }, "testling" : { "files" : "test/*.js", "browsers" : [ "ie/6..latest", "chrome/20..latest", "firefox/10..latest", "safari/latest", "opera/11.0..latest", "iphone/6", "ipad/6" ] }, "repository": { "type": "git", "url": "git://github.com/substack/resumer.git" }, "homepage": "https://github.com/substack/resumer", "keywords": [ "through", "stream", "pause", "resume" ], "author": { "name": "James Halliday", "email": "mail@substack.net", "url": "http://substack.net" }, "license": "MIT" } resumer-0.0.0/readme.markdown000066400000000000000000000022271214552642100161770ustar00rootroot00000000000000# resumer Return a through stream that starts out paused and resumes on the next tick, unless somebody called `.pause()`. This module has the same signature as [through](https://npmjs.com/package/through). [![browser support](https://ci.testling.com/substack/resumer.png)](http://ci.testling.com/substack/resumer) [![build status](https://secure.travis-ci.org/substack/resumer.png)](http://travis-ci.org/substack/resumer) # example ``` js var resumer = require('resumer'); var s = createStream(); s.pipe(process.stdout); function createStream () { var stream = resumer(); stream.queue('beep boop\n'); return stream; } ``` ``` $ node example/resume.js beep boop ``` # methods ``` js var resumer = require('resumer') ``` ## resumer(write, end) Return a new through stream from `write` and `end`, which default to pass-through `.queue()` functions if not specified. The stream starts out paused and will be resumed on the next tick unless you call `.pause()` first. `write` and `end` get passed directly through to [through](https://npmjs.com/package/through). # install With [npm](https://npmjs.org) do: ``` npm install resumer ``` # license MIT resumer-0.0.0/test/000077500000000000000000000000001214552642100141525ustar00rootroot00000000000000resumer-0.0.0/test/resume.js000066400000000000000000000013621214552642100160120ustar00rootroot00000000000000var test = require('tape'); var resumer = require('../'); var concat = require('concat-stream'); test('implicit resume', function (t) { t.plan(1); var s = createStream(); s.pipe(concat(function (err, body) { t.equal(body, 'beep boop\n'); })); }); test('pause/resume', function (t) { t.plan(2); var s = createStream(); s.pause(); var paused = true; setTimeout(function () { paused = false; s.resume(); }, 100); s.pipe(concat(function (err, body) { t.equal(paused, false); t.equal(body, 'beep boop\n'); })); }); function createStream () { var stream = resumer(); stream.queue('beep boop\n'); stream.queue(null); return stream; } resumer-0.0.0/test/through.js000066400000000000000000000013351214552642100161720ustar00rootroot00000000000000var test = require('tape'); var resumer = require('../'); var concat = require('concat-stream'); test('through write/end', function (t) { t.plan(2); var s = createStream(); s.on('okok', function () { t.ok(true); }); s.pipe(concat(function (err, body) { t.equal(body, 'BEGIN\nRAWR\nEND\n'); })); setTimeout(function () { s.end('rawr\n'); }, 50); }); function createStream () { var stream = resumer(write, end); stream.queue('BEGIN\n'); return stream; function write (x) { this.queue(String(x).toUpperCase()); } function end () { this.emit('okok'); this.queue('END\n'); this.queue(null); } }