package/package.json000644 000765 000024 0000002044 13100675627013024 0ustar00000000 000000 { "name": "lead", "version": "1.0.0", "description": "Sink your streams.", "author": "Gulp Team (http://gulpjs.com/)", "contributors": [ "Blaine Bublitz " ], "repository": "gulpjs/lead", "license": "MIT", "engines": { "node": ">= 0.10" }, "main": "index.js", "files": [ "LICENSE", "index.js" ], "scripts": { "lint": "eslint index.js test/ && jscs index.js test/", "pretest": "npm run lint", "test": "mocha --async-only", "cover": "istanbul cover _mocha --report lcovonly", "coveralls": "npm run cover && istanbul-coveralls" }, "dependencies": { "flush-write-stream": "^1.0.2" }, "devDependencies": { "eslint": "^1.10.3", "eslint-config-gulp": "^2.0.0", "expect": "^1.20.2", "istanbul": "^0.4.3", "istanbul-coveralls": "^1.0.3", "jscs": "^2.4.0", "jscs-preset-gulp": "^1.0.0", "mississippi": "^1.3.0", "mocha": "^3.2.0" }, "keywords": [ "streams", "sink", "through", "writeable" ] } package/README.md000644 000765 000024 0000003510 13100675545012013 0ustar00000000 000000

# lead [![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][travis-image]][travis-url] [![AppVeyor Build Status][appveyor-image]][appveyor-url] [![Coveralls Status][coveralls-image]][coveralls-url] [![Gitter chat][gitter-image]][gitter-url] Sink your streams. ## Usage ```js var from = require('from2'); var through = require('through2'); var sink = require('lead'); // Might be used as a Transform or Writeable var maybeThrough = through(function(chunk, enc, cb) { // processing cb(null, chunk); }); from(['hello', 'world']) // Sink it to behave like a Writeable .pipe(sink(maybeThrough)) ``` ## API ### `sink(stream)` Takes a `stream` to sink and returns the same stream. Sets up event listeners to infer if the stream is being used as a `Transform` or `Writeable` stream and sinks it on `nextTick` if necessary. If the stream is being used as a `Transform` stream but becomes unpiped, it will be sunk. Respects `pipe`, `on('data')` and `on('readable')` handlers. ## License MIT [downloads-image]: http://img.shields.io/npm/dm/lead.svg [npm-url]: https://npmjs.com/package/lead [npm-image]: http://img.shields.io/npm/v/lead.svg [travis-url]: https://travis-ci.org/gulpjs/lead [travis-image]: http://img.shields.io/travis/gulpjs/lead.svg?label=travis-ci [appveyor-url]: https://ci.appveyor.com/project/gulpjs/lead [appveyor-image]: https://img.shields.io/appveyor/ci/gulpjs/lead.svg?label=appveyor [coveralls-url]: https://coveralls.io/r/gulpjs/lead [coveralls-image]: http://img.shields.io/coveralls/gulpjs/lead/master.svg [gitter-url]: https://gitter.im/gulpjs/gulp [gitter-image]: https://badges.gitter.im/gulpjs/gulp.png package/LICENSE000644 000765 000024 0000002214 13100663726011537 0ustar00000000 000000 The MIT License (MIT) Copyright (c) 2017 Blaine Bublitz , Eric Schoffstall and other contributors 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. package/index.js000644 000765 000024 0000002232 13100666757012206 0ustar00000000 000000 'use strict'; var Writable = require('flush-write-stream'); function listenerCount(stream, evt) { return stream.listeners(evt).length; } function hasListeners(stream) { return !!(listenerCount(stream, 'readable') || listenerCount(stream, 'data')); } function sinker(file, enc, callback) { callback(); } function sink(stream) { var sinkAdded = false; var sinkOptions = { objectMode: stream._readableState.objectMode, }; var sinkStream = new Writable(sinkOptions, sinker); function addSink() { if (sinkAdded) { return; } if (hasListeners(stream)) { return; } sinkAdded = true; stream.pipe(sinkStream); } function removeSink(evt) { if (evt !== 'readable' && evt !== 'data') { return; } if (hasListeners(stream)) { sinkAdded = false; stream.unpipe(sinkStream); } } stream.on('newListener', removeSink); stream.on('removeListener', removeSink); stream.on('removeListener', addSink); // Sink the stream to start flowing // Do this on nextTick, it will flow at slowest speed of piped streams process.nextTick(addSink); return stream; } module.exports = sink;