package/package.json000644 000765 000024 0000002100 13102416662013007 0ustar00000000 000000 { "name": "to-through", "version": "2.0.0", "description": "Wrap a ReadableStream in a TransformStream.", "author": "Gulp Team (http://gulpjs.com/)", "contributors": [ "Blaine Bublitz " ], "repository": "gulpjs/to-through", "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": { "through2": "^2.0.3" }, "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": [ "transform", "readable", "through", "wrap" ] } package/README.md000644 000765 000024 0000003707 13102221251012002 0ustar00000000 000000

# to-through [![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] Wrap a ReadableStream in a TransformStream. ## Usage ```js var from = require('from2'); var concat = require('concat-stream'); var toThrough = require('to-through'); var readable = from([' ', 'hello', ' ', 'world']); // Can be used as a Readable or Transform var maybeTransform = toThrough(readable); from(['hi', ' ', 'there', ',']) .pipe(maybeTransform) .pipe(concat(function(result) { // result.toString() === 'hi there, hello world' })); ``` ## API ### `toThrough(readableStream)` Takes a `readableStream` as the only argument and returns a `through2` stream. If the returned stream is piped before `nextTick`, the wrapped `readableStream` will not flow until the upstream is flushed. If the stream is not piped before `nextTick`, it is ended and flushed (acting as a proper readable). ## License MIT [downloads-image]: http://img.shields.io/npm/dm/to-through.svg [npm-url]: https://npmjs.com/package/to-through [npm-image]: http://img.shields.io/npm/v/to-through.svg [travis-url]: https://travis-ci.org/gulpjs/to-through [travis-image]: http://img.shields.io/travis/gulpjs/to-through.svg?label=travis-ci [appveyor-url]: https://ci.appveyor.com/project/gulpjs/to-through [appveyor-image]: https://img.shields.io/appveyor/ci/gulpjs/to-through.svg?label=appveyor [coveralls-url]: https://coveralls.io/r/gulpjs/to-through [coveralls-image]: http://img.shields.io/coveralls/gulpjs/to-through/master.svg [gitter-url]: https://gitter.im/gulpjs/gulp [gitter-image]: https://badges.gitter.im/gulpjs/gulp.png package/LICENSE000644 000765 000024 0000002214 13102167060011527 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 0000002346 13102416645012203 0ustar00000000 000000 'use strict'; var through = require('through2'); function forward(chunk, enc, cb) { cb(null, chunk); } function toThrough(readable) { var opts = { objectMode: readable._readableState.objectMode, highWaterMark: readable._readableState.highWaterMark, }; function flush(cb) { var self = this; readable.on('readable', onReadable); readable.on('end', cb); function onReadable() { var chunk; while (chunk = readable.read()) { self.push(chunk); } } } var wrapper = through(opts, forward, flush); var shouldFlow = true; wrapper.once('pipe', onPipe); wrapper.on('newListener', onListener); readable.on('error', wrapper.emit.bind(wrapper, 'error')); function onListener(event) { // Once we've seen the data or readable event, check if we need to flow if (event === 'data' || event === 'readable') { maybeFlow(); this.removeListener('newListener', onListener); } } function onPipe() { // If the wrapper is piped, disable flow shouldFlow = false; } function maybeFlow() { // If we need to flow, end the stream which triggers flush if (shouldFlow) { wrapper.end(); } } return wrapper; } module.exports = toThrough;