pax_global_header00006660000000000000000000000064125450767520014527gustar00rootroot0000000000000052 comment=ad2d6924b4f90e79511a07a058899172acd3e59b pause-0.1.0/000077500000000000000000000000001254507675200126425ustar00rootroot00000000000000pause-0.1.0/.gitignore000066400000000000000000000000461254507675200146320ustar00rootroot00000000000000coverage/ node_modules/ npm-debug.log pause-0.1.0/.travis.yml000066400000000000000000000010631254507675200147530ustar00rootroot00000000000000language: node_js node_js: - "0.6" - "0.8" - "0.10" sudo: false before_install: # Setup Node.js version-specific dependencies - "test $TRAVIS_NODE_VERSION != '0.6' || npm rm --save-dev istanbul" - "test $TRAVIS_NODE_VERSION != '0.8' || npm rm --save-dev istanbul" script: # Run test script, depending on istanbul install - "test -n $(npm -ps ls istanbul) || npm test" - "test -z $(npm -ps ls istanbul) || npm run-script test-ci" after_script: - "test -e ./coverage/lcov.info && npm install coveralls@2 && cat ./coverage/lcov.info | coveralls" pause-0.1.0/HISTORY.md000066400000000000000000000003061254507675200143240ustar00rootroot000000000000000.1.0 / 2015-07-01 ================== * Re-emit events with all original arguments * Refactor internals * perf: enable strict mode 0.0.1 / 2010-01-03 ================== * Initial release pause-0.1.0/LICENSE000066400000000000000000000022211254507675200136440ustar00rootroot00000000000000(The MIT License) Copyright (c) 2012 TJ Holowaychuk Copyright (c) 2015 Douglas Christopher Wilson 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. pause-0.1.0/README.md000066400000000000000000000025621254507675200141260ustar00rootroot00000000000000# pause [![NPM Version][npm-image]][npm-url] [![NPM Downloads][downloads-image]][downloads-url] [![Node.js Version][node-image]][node-url] [![Build Status][travis-image]][travis-url] [![Test Coverage][coveralls-image]][coveralls-url] Pause a stream's data events ## Installation ```sh $ npm install pause ``` ## API ```js var pause = require('pause') ``` ### handle = pause(stream) Pause the data events on a stream and return a handle to resume or end the stream. #### handle.end() Dispose of the handle. This does not end the stream, but it simply discards the event collection, making `handle.resume()` a no-op. #### handle.resume() Resume the stream by re-emitting all the `data` events in the same order, followed by an `end` event, if that was emitting during the pause. ## License [MIT](LICENSE) [npm-image]: https://img.shields.io/npm/v/pause.svg [npm-url]: https://npmjs.org/package/pause [node-image]: https://img.shields.io/node/v/pause.svg [node-url]: http://nodejs.org/download/ [travis-image]: https://img.shields.io/travis/stream-utils/pause/master.svg [travis-url]: https://travis-ci.org/stream-utils/pause [coveralls-image]: https://img.shields.io/coveralls/stream-utils/pause.svg [coveralls-url]: https://coveralls.io/r/stream-utils/pause?branch=master [downloads-image]: https://img.shields.io/npm/dm/pause.svg [downloads-url]: https://npmjs.org/package/pause pause-0.1.0/index.js000066400000000000000000000020541254507675200143100ustar00rootroot00000000000000/*! * pause * Copyright(c) 2012 TJ Holowaychuk * Copyright(c) 2015 Douglas Christopher Wilson * MIT Licensed */ 'use strict' /** * Module exports. * @public */ module.exports = pause /** * Pause the data events on a stream. * * @param {object} stream * @public */ function pause(stream) { var events = [] var onData = createEventListener('data', events) var onEnd = createEventListener('end', events) // buffer data stream.on('data', onData) // buffer end stream.on('end', onEnd) return { end: function end() { stream.removeListener('data', onData) stream.removeListener('end', onEnd) }, resume: function resume() { this.end() for (var i = 0; i < events.length; i++) { stream.emit.apply(stream, events[i]) } } } } function createEventListener(name, events) { return function onEvent() { var args = new Array(arguments.length + 1) args[0] = name for (var i = 0; i < arguments.length; i++) { args[i + 1] = arguments[i] } events.push(args) } } pause-0.1.0/package.json000066400000000000000000000014541254507675200151340ustar00rootroot00000000000000{ "name": "pause", "description": "Pause a stream's data events", "version": "0.1.0", "author": "TJ Holowaychuk ", "contributors": [ "Douglas Christopher Wilson " ], "license": "MIT", "repository": "stream-utils/pause", "devDependencies": { "after": "0.8.1", "istanbul": "0.3.17", "mocha": "1.21.5" }, "files": [ "HISTORY.md", "LICENSE", "README.md", "index.js" ], "engines": { "node": ">= 0.6" }, "scripts": { "test": "mocha --reporter spec --bail --check-leaks test/", "test-ci": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/", "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/" } } pause-0.1.0/test/000077500000000000000000000000001254507675200136215ustar00rootroot00000000000000pause-0.1.0/test/pause.js000066400000000000000000000052311254507675200152750ustar00rootroot00000000000000 var after = require('after') var assert = require('assert') var pause = require('..') var Stream = require('stream') var util = require('util') describe('pause(stream)', function () { it('should return a handle', function () { var stream = new Stream() var handle = pause(stream) assert.ok(handle && typeof handle === 'object') }) describe('handle.end()', function () { it('should stop collecting events', function (done) { var cb = after(1, done) var stream = new Stream() var handle = pause(stream) stream.emit('data', 'ping') process.nextTick(function () { handle.end() stream.emit('data', 'pong') stream.emit('end') process.nextTick(function () { var expected = [ ['data', 'ping'] ] stream.on('data', function (data) { assert.deepEqual(['data', data], expected.shift()) cb() }) stream.on('end', function () { assert.deepEqual(['end'], expected.shift()) cb() }) handle.resume() }) }) }) }) describe('handle.pause()', function () { it('should re-emit data events', function (done) { var cb = after(2, done) var stream = new Stream() var handle = pause(stream) stream.emit('data', 'ping') stream.emit('data', 'pong', 'utf8') process.nextTick(function () { var expected = [ ['ping', undefined], ['pong', 'utf8'] ] stream.on('data', function (data, encoding) { assert.deepEqual([data, encoding], expected.shift()) cb() }) handle.resume() }) }) it('should re-emit end event', function (done) { var cb = after(1, done) var stream = new Stream() var handle = pause(stream) stream.emit('end') process.nextTick(function () { stream.on('end', cb) handle.resume() }) }) it('should re-emit events in original order', function (done) { var cb = after(3, done) var stream = new Stream() var handle = pause(stream) stream.emit('data', 'ping') stream.emit('data', 'pong') stream.emit('end') process.nextTick(function () { var expected = [ ['data', 'ping'], ['data', 'pong'], ['end'] ] stream.on('data', function (data) { assert.deepEqual(['data', data], expected.shift()) cb() }) stream.on('end', function () { assert.deepEqual(['end'], expected.shift()) cb() }) handle.resume() }) }) }) })