pax_global_header00006660000000000000000000000064131024166620014513gustar00rootroot0000000000000052 comment=535a3896be9b8afb9a435199eb153b089dccd55e to-through-2.0.0/000077500000000000000000000000001310241666200136125ustar00rootroot00000000000000to-through-2.0.0/.editorconfig000066400000000000000000000003051310241666200162650ustar00rootroot00000000000000# http://editorconfig.org root = true [*] indent_style = space indent_size = 2 charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.md] trim_trailing_whitespace = false to-through-2.0.0/.eslintrc000066400000000000000000000000301310241666200154270ustar00rootroot00000000000000{ "extends": "gulp" } to-through-2.0.0/.gitignore000066400000000000000000000012541310241666200156040ustar00rootroot00000000000000# Logs logs *.log # Runtime data pids *.pid *.seed # Directory for instrumented libs generated by jscoverage/JSCover lib-cov # Coverage directory used by tools like istanbul coverage # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) .grunt # Compiled binary addons (http://nodejs.org/api/addons.html) build/Release # Dependency directory # Commenting this out is preferred by some people, see # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git- node_modules # Users Environment Variables .lock-wscript # Garbage files .DS_Store # Generated by integration tests test/fixtures/tmp test/fixtures/out to-through-2.0.0/.jscsrc000066400000000000000000000000271310241666200151010ustar00rootroot00000000000000{ "preset": "gulp" } to-through-2.0.0/.travis.yml000066400000000000000000000001711310241666200157220ustar00rootroot00000000000000sudo: false language: node_js node_js: - '6' - '5' - '4' - '0.12' - '0.10' after_script: - npm run coveralls to-through-2.0.0/LICENSE000066400000000000000000000022141310241666200146160ustar00rootroot00000000000000The 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. to-through-2.0.0/README.md000066400000000000000000000037071310241666200151000ustar00rootroot00000000000000

# 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 to-through-2.0.0/appveyor.yml000066400000000000000000000007211310241666200162020ustar00rootroot00000000000000# http://www.appveyor.com/docs/appveyor-yml # http://www.appveyor.com/docs/lang/nodejs-iojs environment: matrix: # node.js - nodejs_version: "0.10" - nodejs_version: "0.12" - nodejs_version: "4" - nodejs_version: "5" - nodejs_version: "6" install: - ps: Install-Product node $env:nodejs_version - npm install test_script: - node --version - npm --version - cmd: npm test build: off # build version format version: "{build}" to-through-2.0.0/index.js000066400000000000000000000023461310241666200152640ustar00rootroot00000000000000'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; to-through-2.0.0/package.json000066400000000000000000000021001310241666200160710ustar00rootroot00000000000000{ "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" ] } to-through-2.0.0/test/000077500000000000000000000000001310241666200145715ustar00rootroot00000000000000to-through-2.0.0/test/.eslintrc000066400000000000000000000000351310241666200164130ustar00rootroot00000000000000{ "extends": "gulp/test" } to-through-2.0.0/test/index.js000066400000000000000000000074741310241666200162520ustar00rootroot00000000000000'use strict'; var expect = require('expect'); var miss = require('mississippi'); var toThrough = require('../'); var from = miss.from; var pipe = miss.pipe; var concat = miss.concat; describe('toThrough (buffer mode)', function() { // These tests ensure it automatically detects buffer mode var preContents = ['from', ' ', 'upstream', ' ']; var contents = ['hello', ' ', 'world', ' ', '123']; it('can wrap a Readable and be used as a Readable', function(done) { var readable = from(contents); function assert(result) { expect(result).toEqual(contents.join('')); } pipe([ toThrough(readable), concat(assert), ], done); }); it('can wrap a Readable and be used as a Transform', function(done) { var readable = from(contents); function assert(result) { expect(result).toEqual(contents.join('')); } pipe([ from([]), toThrough(readable), concat(assert), ], done); }); it('passes through all upstream before readable', function(done) { var readable = from(contents); function assert(result) { expect(result).toEqual(preContents.concat(contents).join('')); } pipe([ from(preContents), toThrough(readable), concat(assert), ], done); }); it('re-emits errors from readable', function(done) { var readable = from([new Error('boom')]); function assert(err) { expect(err).toExist(); expect(err.message).toEqual('boom'); done(); } pipe([ from(preContents), toThrough(readable), concat(), ], assert); }); it('does not flush the stream if not piped before nextTick', function(done) { var readable = from(contents); var wrapped = toThrough(readable); function assert(result) { expect(result).toEqual(preContents.concat(contents).join('')); } process.nextTick(function() { pipe([ from(preContents), wrapped, concat(assert), ], done); }); }); }); describe('toThrough (object mode)', function() { // These tests ensure it automatically detects objectMode var preContents = [ { value: -2 }, { value: -1 }, { value: 0 }, ]; var contents = [ { value: 1 }, { value: 2 }, { value: 3 }, { value: 4 }, { value: 5 }, { value: 6 }, { value: 7 }, { value: 8 }, { value: 9 }, { value: 10 }, { value: 11 }, { value: 12 }, { value: 13 }, { value: 14 }, { value: 15 }, { value: 16 }, { value: 17 }, { value: 18 }, { value: 19 }, { value: 20 }, ]; it('can wrap a Readable and be used as a Readable', function(done) { var readable = from.obj(contents); function assert(result) { expect(result).toEqual(contents); } pipe([ toThrough(readable), concat(assert), ], done); }); it('can wrap a Readable and be used as a Transform', function(done) { var readable = from.obj(contents); function assert(result) { expect(result).toEqual(contents); } pipe([ from.obj([]), toThrough(readable), concat(assert), ], done); }); it('passes through all upstream before readable', function(done) { var readable = from.obj(contents); function assert(result) { expect(result).toEqual(preContents.concat(contents)); } pipe([ from.obj(preContents), toThrough(readable), concat(assert), ], done); }); it('does not flush the stream if not piped before nextTick', function(done) { var readable = from.obj(contents); var wrapped = toThrough(readable); function assert(result) { expect(result).toEqual(preContents.concat(contents)); } process.nextTick(function() { pipe([ from.obj(preContents), wrapped, concat(assert), ], done); }); }); });