first commit
This commit is contained in:
33
build/node_modules/cloneable-readable/.npmignore
generated
vendored
Normal file
33
build/node_modules/cloneable-readable/.npmignore
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.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
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (http://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directory
|
||||
node_modules
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
8
build/node_modules/cloneable-readable/.travis.yml
generated
vendored
Normal file
8
build/node_modules/cloneable-readable/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
language: node_js
|
||||
sudo: false
|
||||
node_js:
|
||||
- "0.10"
|
||||
- "0.12"
|
||||
- "4"
|
||||
- "5"
|
||||
- "6"
|
||||
21
build/node_modules/cloneable-readable/LICENSE
generated
vendored
Normal file
21
build/node_modules/cloneable-readable/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 Matteo Collina
|
||||
|
||||
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.
|
||||
52
build/node_modules/cloneable-readable/README.md
generated
vendored
Normal file
52
build/node_modules/cloneable-readable/README.md
generated
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
# cloneable-readable
|
||||
|
||||
[](https://travis-ci.org/mcollina/cloneable-readable)
|
||||
|
||||
Clone a Readable stream, safely.
|
||||
|
||||
```js
|
||||
'use strict'
|
||||
|
||||
var cloneable = require('cloneable-readable')
|
||||
var fs = require('fs')
|
||||
var pump = require('pump')
|
||||
|
||||
var stream = cloneable(fs.createReadStream('./package.json'))
|
||||
|
||||
pump(stream.clone(), fs.createWriteStream('./out1'))
|
||||
|
||||
// simulate some asynchronicity
|
||||
setImmediate(function () {
|
||||
pump(stream, fs.createWriteStream('./out2'))
|
||||
})
|
||||
```
|
||||
|
||||
**cloneable-readable** automatically handles `objectMode: true`.
|
||||
|
||||
This module comes out of an healthy discussion on the 'right' way to
|
||||
clone a Readable in https://github.com/gulpjs/vinyl/issues/85
|
||||
and https://github.com/nodejs/readable-stream/issues/202. This is my take.
|
||||
|
||||
**YOU MUST PIPE ALL CLONES TO START THE FLOW**
|
||||
|
||||
You can also attach `'data'` and `'readable'` events to them.
|
||||
|
||||
## API
|
||||
|
||||
### cloneable(stream)
|
||||
|
||||
Create a `Cloneable` stream.
|
||||
A Cloneable has a `clone()` method to create more clones.
|
||||
All clones must be resumed/piped to start the flow.
|
||||
|
||||
### cloneable.isCloneable(stream)
|
||||
|
||||
Check if `stream` needs to be wrapped in a `Cloneable` or not.
|
||||
|
||||
## Acknowledgements
|
||||
|
||||
This project was kindly sponsored by [nearForm](http://nearform.com).
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
14
build/node_modules/cloneable-readable/example.js
generated
vendored
Normal file
14
build/node_modules/cloneable-readable/example.js
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
'use strict'
|
||||
|
||||
var cloneable = require('./')
|
||||
var fs = require('fs')
|
||||
var pump = require('pump')
|
||||
|
||||
var stream = cloneable(fs.createReadStream('./package.json'))
|
||||
|
||||
pump(stream.clone(), fs.createWriteStream('./out1'))
|
||||
|
||||
// simulate some asynchronicity
|
||||
setImmediate(function () {
|
||||
pump(stream, fs.createWriteStream('./out2'))
|
||||
})
|
||||
110
build/node_modules/cloneable-readable/index.js
generated
vendored
Normal file
110
build/node_modules/cloneable-readable/index.js
generated
vendored
Normal file
@@ -0,0 +1,110 @@
|
||||
'use strict'
|
||||
|
||||
var through2 = require('through2')
|
||||
var inherits = require('inherits')
|
||||
var nextTick = require('process-nextick-args')
|
||||
var Ctor = through2.ctor()
|
||||
|
||||
function Cloneable (stream, opts) {
|
||||
if (!(this instanceof Cloneable)) {
|
||||
return new Cloneable(stream, opts)
|
||||
}
|
||||
|
||||
var objectMode = stream._readableState.objectMode
|
||||
this._original = stream
|
||||
this._clonesCount = 1
|
||||
|
||||
opts = opts || {}
|
||||
opts.objectMode = objectMode
|
||||
|
||||
Ctor.call(this, opts)
|
||||
|
||||
forwardDestroy(stream, this)
|
||||
|
||||
this.on('newListener', onData)
|
||||
}
|
||||
|
||||
inherits(Cloneable, Ctor)
|
||||
|
||||
function onData (event, listener) {
|
||||
if (event === 'data' || event === 'readable') {
|
||||
this.removeListener('newListener', onData)
|
||||
nextTick(clonePiped, this)
|
||||
}
|
||||
}
|
||||
|
||||
Cloneable.prototype.clone = function () {
|
||||
if (!this._original) {
|
||||
throw new Error('already started')
|
||||
}
|
||||
|
||||
this._clonesCount++
|
||||
|
||||
// the events added by the clone should not count
|
||||
// for starting the flow
|
||||
this.removeListener('newListener', onData)
|
||||
var clone = new Clone(this)
|
||||
this.on('newListener', onData)
|
||||
|
||||
return clone
|
||||
}
|
||||
|
||||
function forwardDestroy (src, dest) {
|
||||
src.on('error', destroy)
|
||||
src.on('close', destroy)
|
||||
|
||||
function destroy (err) {
|
||||
dest.destroy(err)
|
||||
}
|
||||
}
|
||||
|
||||
function clonePiped (that) {
|
||||
if (--that._clonesCount === 0 && !that._destroyed) {
|
||||
that._original.pipe(that)
|
||||
that._original = undefined
|
||||
}
|
||||
}
|
||||
|
||||
function Clone (parent, opts) {
|
||||
if (!(this instanceof Clone)) {
|
||||
return new Clone(parent, opts)
|
||||
}
|
||||
|
||||
var objectMode = parent._readableState.objectMode
|
||||
|
||||
opts = opts || {}
|
||||
opts.objectMode = objectMode
|
||||
|
||||
this.parent = parent
|
||||
|
||||
Ctor.call(this, opts)
|
||||
|
||||
forwardDestroy(this.parent, this)
|
||||
|
||||
parent.pipe(this)
|
||||
|
||||
// the events added by the clone should not count
|
||||
// for starting the flow
|
||||
// so we add the newListener handle after we are done
|
||||
this.on('newListener', onDataClone)
|
||||
}
|
||||
|
||||
function onDataClone (event, listener) {
|
||||
// We start the flow once all clones are piped or destroyed
|
||||
if (event === 'data' || event === 'readable' || event === 'close') {
|
||||
nextTick(clonePiped, this.parent)
|
||||
this.removeListener('newListener', onDataClone)
|
||||
}
|
||||
}
|
||||
|
||||
inherits(Clone, Ctor)
|
||||
|
||||
Clone.prototype.clone = function () {
|
||||
return this.parent.clone()
|
||||
}
|
||||
|
||||
Cloneable.isCloneable = function (stream) {
|
||||
return stream instanceof Cloneable || stream instanceof Clone
|
||||
}
|
||||
|
||||
module.exports = Cloneable
|
||||
3
build/node_modules/cloneable-readable/node_modules/through2/.npmignore
generated
vendored
Normal file
3
build/node_modules/cloneable-readable/node_modules/through2/.npmignore
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
test
|
||||
.jshintrc
|
||||
.travis.yml
|
||||
336
build/node_modules/cloneable-readable/node_modules/through2/LICENSE.html
generated
vendored
Normal file
336
build/node_modules/cloneable-readable/node_modules/through2/LICENSE.html
generated
vendored
Normal file
@@ -0,0 +1,336 @@
|
||||
<!doctype html>
|
||||
<!-- Created with GFM2HTML: https://github.com/rvagg/gfm2html -->
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<title></title>
|
||||
<meta name="description" content="">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="created-with" content="https://github.com/rvagg/gfm2html">
|
||||
|
||||
<style type="text/css">
|
||||
/* most of normalize.css */
|
||||
article,aside,details,figcaption,figure,footer,header,hgroup,main,nav,section,summary{display:block;}[hidden],template{display:none;}html{font-family:sans-serif;/*1*/-ms-text-size-adjust:100%;/*2*/-webkit-text-size-adjust:100%;/*2*/}body{margin:0;}a{background:transparent;}a:focus{outline:thindotted;}a:active,a:hover{outline:0;}h1{font-size:2em;margin:0.67em0;}abbr[title]{border-bottom:1pxdotted;}b,strong{font-weight:bold;}dfn{font-style:italic;}hr{-moz-box-sizing:content-box;box-sizing:content-box;height:0;}mark{background:#ff0;color:#000;}code,kbd,pre,samp{font-family:monospace,serif;font-size:1em;}pre{white-space:pre-wrap;}q{quotes:"\201C""\201D""\2018""\2019";}small{font-size:80%;}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline;}sup{top:-0.5em;}sub{bottom:-0.25em;}img{border:0;}svg:not(:root){overflow:hidden;}table{border-collapse:collapse;border-spacing:0;}
|
||||
|
||||
html {
|
||||
font: 14px 'Helvetica Neue', Helvetica, arial, freesans, clean, sans-serif;
|
||||
}
|
||||
|
||||
.container {
|
||||
line-height: 1.6;
|
||||
color: #333;
|
||||
background: #eee;
|
||||
border-radius: 3px;
|
||||
padding: 3px;
|
||||
width: 790px;
|
||||
margin: 10px auto;
|
||||
}
|
||||
|
||||
.body-content {
|
||||
background-color: #fff;
|
||||
border: 1px solid #CACACA;
|
||||
padding: 30px;
|
||||
}
|
||||
|
||||
.body-content > *:first-child {
|
||||
margin-top: 0 !important;
|
||||
}
|
||||
|
||||
a, a:visited {
|
||||
color: #4183c4;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
p, blockquote, ul, ol, dl, table, pre {
|
||||
margin: 15px 0;
|
||||
}
|
||||
|
||||
.markdown-body h1
|
||||
, .markdown-body h2
|
||||
, .markdown-body h3
|
||||
, .markdown-body h4
|
||||
, .markdown-body h5
|
||||
, .markdown-body h6 {
|
||||
margin: 20px 0 10px;
|
||||
padding: 0;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 2.5em;
|
||||
color: #000;
|
||||
border-bottom: 1px solid #ddd;
|
||||
}
|
||||
|
||||
h2 {
|
||||
font-size: 2em;
|
||||
border-bottom: 1px solid #eee;
|
||||
color: #000;
|
||||
}
|
||||
|
||||
img {
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
hr {
|
||||
background: transparent url("/img/hr.png") repeat-x 0 0;
|
||||
border: 0 none;
|
||||
color: #ccc;
|
||||
height: 4px;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
border-spacing: 0;
|
||||
}
|
||||
|
||||
tr:nth-child(2n) {
|
||||
background-color: #f8f8f8;
|
||||
}
|
||||
|
||||
.markdown-body tr {
|
||||
border-top: 1px solid #ccc;
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
td, th {
|
||||
border: 1px solid #ccc;
|
||||
padding: 6px 13px;
|
||||
}
|
||||
|
||||
th {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
blockquote {
|
||||
border-left: 4px solid #ddd;
|
||||
padding: 0 15px;
|
||||
color: #777;
|
||||
}
|
||||
|
||||
blockquote > :last-child, blockquote > :first-child {
|
||||
margin-bottom: 0px;
|
||||
}
|
||||
|
||||
pre, code {
|
||||
font-size: 13px;
|
||||
font-family: 'UbuntuMono', monospace;
|
||||
white-space: nowrap;
|
||||
margin: 0 2px;
|
||||
padding: 0px 5px;
|
||||
border: 1px solid #eaeaea;
|
||||
background-color: #f8f8f8;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
pre > code {
|
||||
white-space: pre;
|
||||
}
|
||||
|
||||
pre {
|
||||
overflow-x: auto;
|
||||
white-space: pre;
|
||||
padding: 10px;
|
||||
line-height: 150%;
|
||||
background-color: #f8f8f8;
|
||||
border-color: #ccc;
|
||||
}
|
||||
|
||||
pre code, pre tt {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
background-color: transparent;
|
||||
border: none;
|
||||
}
|
||||
|
||||
.highlight .c
|
||||
, .highlight .cm
|
||||
, .highlight .cp
|
||||
, .highlight .c1 {
|
||||
color:#999988;
|
||||
font-style:italic;
|
||||
}
|
||||
|
||||
.highlight .err {
|
||||
color:#a61717;
|
||||
background-color:#e3d2d2
|
||||
}
|
||||
|
||||
.highlight .o
|
||||
, .highlight .gs
|
||||
, .highlight .kc
|
||||
, .highlight .kd
|
||||
, .highlight .kn
|
||||
, .highlight .kp
|
||||
, .highlight .kr {
|
||||
font-weight:bold
|
||||
}
|
||||
|
||||
.highlight .cs {
|
||||
color:#999999;
|
||||
font-weight:bold;
|
||||
font-style:italic
|
||||
}
|
||||
|
||||
.highlight .gd {
|
||||
color:#000000;
|
||||
background-color:#ffdddd
|
||||
}
|
||||
|
||||
.highlight .gd .x {
|
||||
color:#000000;
|
||||
background-color:#ffaaaa
|
||||
}
|
||||
|
||||
.highlight .ge {
|
||||
font-style:italic
|
||||
}
|
||||
|
||||
.highlight .gr
|
||||
, .highlight .gt {
|
||||
color:#aa0000
|
||||
}
|
||||
|
||||
.highlight .gh
|
||||
, .highlight .bp {
|
||||
color:#999999
|
||||
}
|
||||
|
||||
.highlight .gi {
|
||||
color:#000000;
|
||||
background-color:#ddffdd
|
||||
}
|
||||
|
||||
.highlight .gi .x {
|
||||
color:#000000;
|
||||
background-color:#aaffaa
|
||||
}
|
||||
|
||||
.highlight .go {
|
||||
color:#888888
|
||||
}
|
||||
|
||||
.highlight .gp
|
||||
, .highlight .nn {
|
||||
color:#555555
|
||||
}
|
||||
|
||||
|
||||
.highlight .gu {
|
||||
color:#800080;
|
||||
font-weight:bold
|
||||
}
|
||||
|
||||
|
||||
.highlight .kt {
|
||||
color:#445588;
|
||||
font-weight:bold
|
||||
}
|
||||
|
||||
.highlight .m
|
||||
, .highlight .mf
|
||||
, .highlight .mh
|
||||
, .highlight .mi
|
||||
, .highlight .mo
|
||||
, .highlight .il {
|
||||
color:#009999
|
||||
}
|
||||
|
||||
.highlight .s
|
||||
, .highlight .sb
|
||||
, .highlight .sc
|
||||
, .highlight .sd
|
||||
, .highlight .s2
|
||||
, .highlight .se
|
||||
, .highlight .sh
|
||||
, .highlight .si
|
||||
, .highlight .sx
|
||||
, .highlight .s1 {
|
||||
color:#d14
|
||||
}
|
||||
|
||||
.highlight .n {
|
||||
color:#333333
|
||||
}
|
||||
|
||||
.highlight .na
|
||||
, .highlight .no
|
||||
, .highlight .nv
|
||||
, .highlight .vc
|
||||
, .highlight .vg
|
||||
, .highlight .vi
|
||||
, .highlight .nb {
|
||||
color:#0086B3
|
||||
}
|
||||
|
||||
.highlight .nc {
|
||||
color:#445588;
|
||||
font-weight:bold
|
||||
}
|
||||
|
||||
.highlight .ni {
|
||||
color:#800080
|
||||
}
|
||||
|
||||
.highlight .ne
|
||||
, .highlight .nf {
|
||||
color:#990000;
|
||||
font-weight:bold
|
||||
}
|
||||
|
||||
.highlight .nt {
|
||||
color:#000080
|
||||
}
|
||||
|
||||
.highlight .ow {
|
||||
font-weight:bold
|
||||
}
|
||||
|
||||
.highlight .w {
|
||||
color:#bbbbbb
|
||||
}
|
||||
|
||||
.highlight .sr {
|
||||
color:#009926
|
||||
}
|
||||
|
||||
.highlight .ss {
|
||||
color:#990073
|
||||
}
|
||||
|
||||
.highlight .gc {
|
||||
color:#999;
|
||||
background-color:#EAF2F5
|
||||
}
|
||||
|
||||
@media print {
|
||||
.container {
|
||||
background: transparent;
|
||||
border-radius: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.body-content {
|
||||
border: none;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="body-content"><h1 id="the-mit-license-mit-">The MIT License (MIT)</h1>
|
||||
<p><strong>Copyright (c) 2016 Rod Vagg (the "Original Author") and additional contributors</strong></p>
|
||||
<p>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:</p>
|
||||
<p>The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.</p>
|
||||
<p>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.</p>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
9
build/node_modules/cloneable-readable/node_modules/through2/LICENSE.md
generated
vendored
Normal file
9
build/node_modules/cloneable-readable/node_modules/through2/LICENSE.md
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
# The MIT License (MIT)
|
||||
|
||||
**Copyright (c) 2016 Rod Vagg (the "Original Author") and additional 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.
|
||||
136
build/node_modules/cloneable-readable/node_modules/through2/README.md
generated
vendored
Normal file
136
build/node_modules/cloneable-readable/node_modules/through2/README.md
generated
vendored
Normal file
@@ -0,0 +1,136 @@
|
||||
# through2
|
||||
|
||||
[](https://nodei.co/npm/through2/)
|
||||
|
||||
**A tiny wrapper around Node streams.Transform (Streams2) to avoid explicit subclassing noise**
|
||||
|
||||
Inspired by [Dominic Tarr](https://github.com/dominictarr)'s [through](https://github.com/dominictarr/through) in that it's so much easier to make a stream out of a function than it is to set up the prototype chain properly: `through(function (chunk) { ... })`.
|
||||
|
||||
Note: As 2.x.x this module starts using **Streams3** instead of Stream2. To continue using a Streams2 version use `npm install through2@0` to fetch the latest version of 0.x.x. More information about Streams2 vs Streams3 and recommendations see the article **[Why I don't use Node's core 'stream' module](http://r.va.gg/2014/06/why-i-dont-use-nodes-core-stream-module.html)**.
|
||||
|
||||
```js
|
||||
fs.createReadStream('ex.txt')
|
||||
.pipe(through2(function (chunk, enc, callback) {
|
||||
for (var i = 0; i < chunk.length; i++)
|
||||
if (chunk[i] == 97)
|
||||
chunk[i] = 122 // swap 'a' for 'z'
|
||||
|
||||
this.push(chunk)
|
||||
|
||||
callback()
|
||||
}))
|
||||
.pipe(fs.createWriteStream('out.txt'))
|
||||
.on('finish', function () {
|
||||
doSomethingSpecial()
|
||||
})
|
||||
```
|
||||
|
||||
Or object streams:
|
||||
|
||||
```js
|
||||
var all = []
|
||||
|
||||
fs.createReadStream('data.csv')
|
||||
.pipe(csv2())
|
||||
.pipe(through2.obj(function (chunk, enc, callback) {
|
||||
var data = {
|
||||
name : chunk[0]
|
||||
, address : chunk[3]
|
||||
, phone : chunk[10]
|
||||
}
|
||||
this.push(data)
|
||||
|
||||
callback()
|
||||
}))
|
||||
.on('data', function (data) {
|
||||
all.push(data)
|
||||
})
|
||||
.on('end', function () {
|
||||
doSomethingSpecial(all)
|
||||
})
|
||||
```
|
||||
|
||||
Note that `through2.obj(fn)` is a convenience wrapper around `through2({ objectMode: true }, fn)`.
|
||||
|
||||
## API
|
||||
|
||||
<b><code>through2([ options, ] [ transformFunction ] [, flushFunction ])</code></b>
|
||||
|
||||
Consult the **[stream.Transform](http://nodejs.org/docs/latest/api/stream.html#stream_class_stream_transform)** documentation for the exact rules of the `transformFunction` (i.e. `this._transform`) and the optional `flushFunction` (i.e. `this._flush`).
|
||||
|
||||
### options
|
||||
|
||||
The options argument is optional and is passed straight through to `stream.Transform`. So you can use `objectMode:true` if you are processing non-binary streams (or just use `through2.obj()`).
|
||||
|
||||
The `options` argument is first, unlike standard convention, because if I'm passing in an anonymous function then I'd prefer for the options argument to not get lost at the end of the call:
|
||||
|
||||
```js
|
||||
fs.createReadStream('/tmp/important.dat')
|
||||
.pipe(through2({ objectMode: true, allowHalfOpen: false },
|
||||
function (chunk, enc, cb) {
|
||||
cb(null, 'wut?') // note we can use the second argument on the callback
|
||||
// to provide data as an alternative to this.push('wut?')
|
||||
}
|
||||
)
|
||||
.pipe(fs.createWriteStream('/tmp/wut.txt'))
|
||||
```
|
||||
|
||||
### transformFunction
|
||||
|
||||
The `transformFunction` must have the following signature: `function (chunk, encoding, callback) {}`. A minimal implementation should call the `callback` function to indicate that the transformation is done, even if that transformation means discarding the chunk.
|
||||
|
||||
To queue a new chunk, call `this.push(chunk)`—this can be called as many times as required before the `callback()` if you have multiple pieces to send on.
|
||||
|
||||
Alternatively, you may use `callback(err, chunk)` as shorthand for emitting a single chunk or an error.
|
||||
|
||||
If you **do not provide a `transformFunction`** then you will get a simple pass-through stream.
|
||||
|
||||
### flushFunction
|
||||
|
||||
The optional `flushFunction` is provided as the last argument (2nd or 3rd, depending on whether you've supplied options) is called just prior to the stream ending. Can be used to finish up any processing that may be in progress.
|
||||
|
||||
```js
|
||||
fs.createReadStream('/tmp/important.dat')
|
||||
.pipe(through2(
|
||||
function (chunk, enc, cb) { cb(null, chunk) }, // transform is a noop
|
||||
function (cb) { // flush function
|
||||
this.push('tacking on an extra buffer to the end');
|
||||
cb();
|
||||
}
|
||||
))
|
||||
.pipe(fs.createWriteStream('/tmp/wut.txt'));
|
||||
```
|
||||
|
||||
<b><code>through2.ctor([ options, ] transformFunction[, flushFunction ])</code></b>
|
||||
|
||||
Instead of returning a `stream.Transform` instance, `through2.ctor()` returns a **constructor** for a custom Transform. This is useful when you want to use the same transform logic in multiple instances.
|
||||
|
||||
```js
|
||||
var FToC = through2.ctor({objectMode: true}, function (record, encoding, callback) {
|
||||
if (record.temp != null && record.unit == "F") {
|
||||
record.temp = ( ( record.temp - 32 ) * 5 ) / 9
|
||||
record.unit = "C"
|
||||
}
|
||||
this.push(record)
|
||||
callback()
|
||||
})
|
||||
|
||||
// Create instances of FToC like so:
|
||||
var converter = new FToC()
|
||||
// Or:
|
||||
var converter = FToC()
|
||||
// Or specify/override options when you instantiate, if you prefer:
|
||||
var converter = FToC({objectMode: true})
|
||||
```
|
||||
|
||||
## See Also
|
||||
|
||||
- [through2-map](https://github.com/brycebaril/through2-map) - Array.prototype.map analog for streams.
|
||||
- [through2-filter](https://github.com/brycebaril/through2-filter) - Array.prototype.filter analog for streams.
|
||||
- [through2-reduce](https://github.com/brycebaril/through2-reduce) - Array.prototype.reduce analog for streams.
|
||||
- [through2-spy](https://github.com/brycebaril/through2-spy) - Wrapper for simple stream.PassThrough spies.
|
||||
- the [mississippi stream utility collection](https://github.com/maxogden/mississippi) includes `through2` as well as many more useful stream modules similar to this one
|
||||
|
||||
## License
|
||||
|
||||
**through2** is Copyright (c) 2013 Rod Vagg [@rvagg](https://twitter.com/rvagg) and licensed under the MIT license. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE file for more details.
|
||||
65
build/node_modules/cloneable-readable/node_modules/through2/package.json
generated
vendored
Normal file
65
build/node_modules/cloneable-readable/node_modules/through2/package.json
generated
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
{
|
||||
"_from": "through2@^2.0.1",
|
||||
"_id": "through2@2.0.3",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-AARWmzfHx0ujnEPzzteNGtlBQL4=",
|
||||
"_location": "/cloneable-readable/through2",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "through2@^2.0.1",
|
||||
"name": "through2",
|
||||
"escapedName": "through2",
|
||||
"rawSpec": "^2.0.1",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^2.0.1"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/cloneable-readable"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/through2/-/through2-2.0.3.tgz",
|
||||
"_shasum": "0004569b37c7c74ba39c43f3ced78d1ad94140be",
|
||||
"_spec": "through2@^2.0.1",
|
||||
"_where": "/Users/asciidisco/Desktop/asciidisco.com/build/node_modules/cloneable-readable",
|
||||
"author": {
|
||||
"name": "Rod Vagg",
|
||||
"email": "r@va.gg",
|
||||
"url": "https://github.com/rvagg"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/rvagg/through2/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"readable-stream": "^2.1.5",
|
||||
"xtend": "~4.0.1"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "A tiny wrapper around Node streams2 Transform to avoid explicit subclassing noise",
|
||||
"devDependencies": {
|
||||
"bl": "~1.1.2",
|
||||
"faucet": "0.0.1",
|
||||
"stream-spigot": "~3.0.5",
|
||||
"tape": "~4.6.2"
|
||||
},
|
||||
"homepage": "https://github.com/rvagg/through2#readme",
|
||||
"keywords": [
|
||||
"stream",
|
||||
"streams2",
|
||||
"through",
|
||||
"transform"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "through2.js",
|
||||
"name": "through2",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/rvagg/through2.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node test/test.js | faucet",
|
||||
"test-local": "brtapsauce-local test/basic-test.js"
|
||||
},
|
||||
"version": "2.0.3"
|
||||
}
|
||||
96
build/node_modules/cloneable-readable/node_modules/through2/through2.js
generated
vendored
Normal file
96
build/node_modules/cloneable-readable/node_modules/through2/through2.js
generated
vendored
Normal file
@@ -0,0 +1,96 @@
|
||||
var Transform = require('readable-stream/transform')
|
||||
, inherits = require('util').inherits
|
||||
, xtend = require('xtend')
|
||||
|
||||
function DestroyableTransform(opts) {
|
||||
Transform.call(this, opts)
|
||||
this._destroyed = false
|
||||
}
|
||||
|
||||
inherits(DestroyableTransform, Transform)
|
||||
|
||||
DestroyableTransform.prototype.destroy = function(err) {
|
||||
if (this._destroyed) return
|
||||
this._destroyed = true
|
||||
|
||||
var self = this
|
||||
process.nextTick(function() {
|
||||
if (err)
|
||||
self.emit('error', err)
|
||||
self.emit('close')
|
||||
})
|
||||
}
|
||||
|
||||
// a noop _transform function
|
||||
function noop (chunk, enc, callback) {
|
||||
callback(null, chunk)
|
||||
}
|
||||
|
||||
|
||||
// create a new export function, used by both the main export and
|
||||
// the .ctor export, contains common logic for dealing with arguments
|
||||
function through2 (construct) {
|
||||
return function (options, transform, flush) {
|
||||
if (typeof options == 'function') {
|
||||
flush = transform
|
||||
transform = options
|
||||
options = {}
|
||||
}
|
||||
|
||||
if (typeof transform != 'function')
|
||||
transform = noop
|
||||
|
||||
if (typeof flush != 'function')
|
||||
flush = null
|
||||
|
||||
return construct(options, transform, flush)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// main export, just make me a transform stream!
|
||||
module.exports = through2(function (options, transform, flush) {
|
||||
var t2 = new DestroyableTransform(options)
|
||||
|
||||
t2._transform = transform
|
||||
|
||||
if (flush)
|
||||
t2._flush = flush
|
||||
|
||||
return t2
|
||||
})
|
||||
|
||||
|
||||
// make me a reusable prototype that I can `new`, or implicitly `new`
|
||||
// with a constructor call
|
||||
module.exports.ctor = through2(function (options, transform, flush) {
|
||||
function Through2 (override) {
|
||||
if (!(this instanceof Through2))
|
||||
return new Through2(override)
|
||||
|
||||
this.options = xtend(options, override)
|
||||
|
||||
DestroyableTransform.call(this, this.options)
|
||||
}
|
||||
|
||||
inherits(Through2, DestroyableTransform)
|
||||
|
||||
Through2.prototype._transform = transform
|
||||
|
||||
if (flush)
|
||||
Through2.prototype._flush = flush
|
||||
|
||||
return Through2
|
||||
})
|
||||
|
||||
|
||||
module.exports.obj = through2(function (options, transform, flush) {
|
||||
var t2 = new DestroyableTransform(xtend({ objectMode: true, highWaterMark: 16 }, options))
|
||||
|
||||
t2._transform = transform
|
||||
|
||||
if (flush)
|
||||
t2._flush = flush
|
||||
|
||||
return t2
|
||||
})
|
||||
70
build/node_modules/cloneable-readable/package.json
generated
vendored
Normal file
70
build/node_modules/cloneable-readable/package.json
generated
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
{
|
||||
"_from": "cloneable-readable@^1.0.0",
|
||||
"_id": "cloneable-readable@1.0.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-pikNQT8hemEjL5XkWP84QYz7ARc=",
|
||||
"_location": "/cloneable-readable",
|
||||
"_phantomChildren": {
|
||||
"readable-stream": "2.3.3",
|
||||
"xtend": "4.0.1"
|
||||
},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "cloneable-readable@^1.0.0",
|
||||
"name": "cloneable-readable",
|
||||
"escapedName": "cloneable-readable",
|
||||
"rawSpec": "^1.0.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^1.0.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/google-closure-compiler-js/vinyl"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/cloneable-readable/-/cloneable-readable-1.0.0.tgz",
|
||||
"_shasum": "a6290d413f217a61232f95e458ff38418cfb0117",
|
||||
"_spec": "cloneable-readable@^1.0.0",
|
||||
"_where": "/Users/asciidisco/Desktop/asciidisco.com/build/node_modules/google-closure-compiler-js/node_modules/vinyl",
|
||||
"author": {
|
||||
"name": "Matteo Collina",
|
||||
"email": "hello@matteocollina.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/mcollina/cloneable-readable/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"inherits": "^2.0.1",
|
||||
"process-nextick-args": "^1.0.6",
|
||||
"through2": "^2.0.1"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "Clone a Readable stream, safely",
|
||||
"devDependencies": {
|
||||
"flush-write-stream": "^1.0.0",
|
||||
"from2": "^2.1.1",
|
||||
"pre-commit": "^1.1.2",
|
||||
"readable-stream": "^2.1.0",
|
||||
"standard": "^8.0.0",
|
||||
"tap-spec": "^4.1.1",
|
||||
"tape": "^4.6.0"
|
||||
},
|
||||
"homepage": "https://github.com/mcollina/cloneable-readable#readme",
|
||||
"keywords": [
|
||||
"readable",
|
||||
"stream",
|
||||
"clone"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"name": "cloneable-readable",
|
||||
"precommit": "test",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/mcollina/cloneable-readable.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "standard && tape test.js | tap-spec"
|
||||
},
|
||||
"version": "1.0.0"
|
||||
}
|
||||
576
build/node_modules/cloneable-readable/test.js
generated
vendored
Normal file
576
build/node_modules/cloneable-readable/test.js
generated
vendored
Normal file
@@ -0,0 +1,576 @@
|
||||
'use strict'
|
||||
|
||||
var test = require('tape').test
|
||||
var from = require('from2')
|
||||
var sink = require('flush-write-stream')
|
||||
var cloneable = require('./')
|
||||
|
||||
test('basic passthrough', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
var read = false
|
||||
var source = from(function (size, next) {
|
||||
if (read) {
|
||||
this.push(null)
|
||||
} else {
|
||||
read = true
|
||||
this.push('hello world')
|
||||
}
|
||||
next()
|
||||
})
|
||||
|
||||
var instance = cloneable(source)
|
||||
t.notOk(read, 'stream not started')
|
||||
|
||||
instance.pipe(sink(function (chunk, enc, cb) {
|
||||
t.equal(chunk.toString(), 'hello world', 'chunk matches')
|
||||
cb()
|
||||
}))
|
||||
})
|
||||
|
||||
test('clone sync', function (t) {
|
||||
t.plan(4)
|
||||
|
||||
var read = false
|
||||
var source = from(function (size, next) {
|
||||
if (read) {
|
||||
this.push(null)
|
||||
} else {
|
||||
read = true
|
||||
this.push('hello world')
|
||||
}
|
||||
next()
|
||||
})
|
||||
|
||||
var instance = cloneable(source)
|
||||
t.notOk(read, 'stream not started')
|
||||
|
||||
var cloned = instance.clone()
|
||||
t.notOk(read, 'stream not started')
|
||||
|
||||
instance.pipe(sink(function (chunk, enc, cb) {
|
||||
t.equal(chunk.toString(), 'hello world', 'chunk matches')
|
||||
cb()
|
||||
}))
|
||||
|
||||
cloned.pipe(sink(function (chunk, enc, cb) {
|
||||
t.equal(chunk.toString(), 'hello world', 'chunk matches')
|
||||
cb()
|
||||
}))
|
||||
})
|
||||
|
||||
test('clone async', function (t) {
|
||||
t.plan(4)
|
||||
|
||||
var read = false
|
||||
var source = from(function (size, next) {
|
||||
if (read) {
|
||||
this.push(null)
|
||||
} else {
|
||||
read = true
|
||||
this.push('hello world')
|
||||
}
|
||||
next()
|
||||
})
|
||||
|
||||
var instance = cloneable(source)
|
||||
t.notOk(read, 'stream not started')
|
||||
|
||||
var cloned = instance.clone()
|
||||
t.notOk(read, 'stream not started')
|
||||
|
||||
instance.pipe(sink(function (chunk, enc, cb) {
|
||||
t.equal(chunk.toString(), 'hello world', 'chunk matches')
|
||||
cb()
|
||||
}))
|
||||
|
||||
setImmediate(function () {
|
||||
cloned.pipe(sink(function (chunk, enc, cb) {
|
||||
t.equal(chunk.toString(), 'hello world', 'chunk matches')
|
||||
cb()
|
||||
}))
|
||||
})
|
||||
})
|
||||
|
||||
test('basic passthrough in obj mode', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
var read = false
|
||||
var source = from.obj(function (size, next) {
|
||||
if (read) {
|
||||
return this.push(null)
|
||||
} else {
|
||||
read = true
|
||||
this.push({ hello: 'world' })
|
||||
}
|
||||
next()
|
||||
})
|
||||
|
||||
var instance = cloneable(source)
|
||||
t.notOk(read, 'stream not started')
|
||||
|
||||
instance.pipe(sink.obj(function (chunk, enc, cb) {
|
||||
t.deepEqual(chunk, { hello: 'world' }, 'chunk matches')
|
||||
cb()
|
||||
}))
|
||||
})
|
||||
|
||||
test('multiple clone in object mode', function (t) {
|
||||
t.plan(4)
|
||||
|
||||
var read = false
|
||||
var source = from.obj(function (size, next) {
|
||||
if (read) {
|
||||
return this.push(null)
|
||||
} else {
|
||||
read = true
|
||||
this.push({ hello: 'world' })
|
||||
}
|
||||
next()
|
||||
})
|
||||
|
||||
var instance = cloneable(source)
|
||||
t.notOk(read, 'stream not started')
|
||||
|
||||
var cloned = instance.clone()
|
||||
t.notOk(read, 'stream not started')
|
||||
|
||||
instance.pipe(sink.obj(function (chunk, enc, cb) {
|
||||
t.deepEqual(chunk, { hello: 'world' }, 'chunk matches')
|
||||
cb()
|
||||
}))
|
||||
|
||||
setImmediate(function () {
|
||||
cloned.pipe(sink.obj(function (chunk, enc, cb) {
|
||||
t.deepEqual(chunk, { hello: 'world' }, 'chunk matches')
|
||||
cb()
|
||||
}))
|
||||
})
|
||||
})
|
||||
|
||||
test('basic passthrough with data event', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
var read = false
|
||||
var source = from(function (size, next) {
|
||||
if (read) {
|
||||
this.push(null)
|
||||
} else {
|
||||
read = true
|
||||
this.push('hello world')
|
||||
}
|
||||
next()
|
||||
})
|
||||
|
||||
var instance = cloneable(source)
|
||||
t.notOk(read, 'stream not started')
|
||||
|
||||
var data = ''
|
||||
instance.on('data', function (chunk) {
|
||||
data += chunk.toString()
|
||||
})
|
||||
|
||||
instance.on('end', function () {
|
||||
t.equal(data, 'hello world', 'chunk matches')
|
||||
})
|
||||
})
|
||||
|
||||
test('basic passthrough with data event on clone', function (t) {
|
||||
t.plan(3)
|
||||
|
||||
var read = false
|
||||
var source = from(function (size, next) {
|
||||
if (read) {
|
||||
this.push(null)
|
||||
} else {
|
||||
read = true
|
||||
this.push('hello world')
|
||||
}
|
||||
next()
|
||||
})
|
||||
|
||||
var instance = cloneable(source)
|
||||
var cloned = instance.clone()
|
||||
|
||||
t.notOk(read, 'stream not started')
|
||||
|
||||
var data = ''
|
||||
cloned.on('data', function (chunk) {
|
||||
data += chunk.toString()
|
||||
})
|
||||
|
||||
cloned.on('end', function () {
|
||||
t.equal(data, 'hello world', 'chunk matches in clone')
|
||||
})
|
||||
|
||||
instance.pipe(sink(function (chunk, enc, cb) {
|
||||
t.equal(chunk.toString(), 'hello world', 'chunk matches in instance')
|
||||
cb()
|
||||
}))
|
||||
})
|
||||
|
||||
test('errors if cloned after start', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
var source = from(function (size, next) {
|
||||
this.push('hello world')
|
||||
this.push(null)
|
||||
next()
|
||||
})
|
||||
|
||||
var instance = cloneable(source)
|
||||
|
||||
instance.pipe(sink(function (chunk, enc, cb) {
|
||||
t.equal(chunk.toString(), 'hello world', 'chunk matches')
|
||||
t.throws(function () {
|
||||
instance.clone()
|
||||
}, 'throws if cloned after start')
|
||||
cb()
|
||||
}))
|
||||
})
|
||||
|
||||
test('basic passthrough with readable event', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
var read = false
|
||||
var source = from(function (size, next) {
|
||||
if (read) {
|
||||
this.push(null)
|
||||
} else {
|
||||
read = true
|
||||
this.push('hello world')
|
||||
}
|
||||
next()
|
||||
})
|
||||
|
||||
var instance = cloneable(source)
|
||||
t.notOk(read, 'stream not started')
|
||||
|
||||
var data = ''
|
||||
instance.on('readable', function () {
|
||||
var chunk
|
||||
while ((chunk = this.read()) !== null) {
|
||||
data += chunk.toString()
|
||||
}
|
||||
})
|
||||
|
||||
instance.on('end', function () {
|
||||
t.equal(data, 'hello world', 'chunk matches')
|
||||
})
|
||||
})
|
||||
|
||||
test('basic passthrough with readable event on clone', function (t) {
|
||||
t.plan(3)
|
||||
|
||||
var read = false
|
||||
var source = from(function (size, next) {
|
||||
if (read) {
|
||||
this.push(null)
|
||||
} else {
|
||||
read = true
|
||||
this.push('hello world')
|
||||
}
|
||||
next()
|
||||
})
|
||||
|
||||
var instance = cloneable(source)
|
||||
var cloned = instance.clone()
|
||||
|
||||
t.notOk(read, 'stream not started')
|
||||
|
||||
var data = ''
|
||||
cloned.on('readable', function () {
|
||||
var chunk
|
||||
while ((chunk = this.read()) !== null) {
|
||||
data += chunk.toString()
|
||||
}
|
||||
})
|
||||
|
||||
cloned.on('end', function () {
|
||||
t.equal(data, 'hello world', 'chunk matches in clone')
|
||||
})
|
||||
|
||||
instance.pipe(sink(function (chunk, enc, cb) {
|
||||
t.equal(chunk.toString(), 'hello world', 'chunk matches in instance')
|
||||
cb()
|
||||
}))
|
||||
})
|
||||
|
||||
test('source error destroys all', function (t) {
|
||||
t.plan(5)
|
||||
|
||||
var source = from()
|
||||
var instance = cloneable(source)
|
||||
var clone = instance.clone()
|
||||
|
||||
source.on('error', function (err) {
|
||||
t.ok(err, 'source errors')
|
||||
|
||||
instance.on('error', function (err2) {
|
||||
t.ok(err === err2, 'instance receives same error')
|
||||
})
|
||||
|
||||
instance.on('close', function () {
|
||||
t.pass('instance is closed')
|
||||
})
|
||||
|
||||
clone.on('error', function (err3) {
|
||||
t.ok(err === err3, 'clone receives same error')
|
||||
})
|
||||
|
||||
clone.on('close', function () {
|
||||
t.pass('clone is closed')
|
||||
})
|
||||
})
|
||||
|
||||
source.emit('error', new Error())
|
||||
})
|
||||
|
||||
test('source destroy destroys all', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
var source = from()
|
||||
var instance = cloneable(source)
|
||||
var clone = instance.clone()
|
||||
|
||||
instance.on('close', function () {
|
||||
t.pass('instance is closed')
|
||||
})
|
||||
|
||||
clone.on('close', function () {
|
||||
t.pass('clone is closed')
|
||||
})
|
||||
|
||||
source.destroy()
|
||||
})
|
||||
|
||||
test('instance error destroys all but the source', function (t) {
|
||||
t.plan(4)
|
||||
|
||||
var source = from()
|
||||
var instance = cloneable(source)
|
||||
var clone = instance.clone()
|
||||
|
||||
source.on('close', function () {
|
||||
t.fail('source should not be closed')
|
||||
})
|
||||
|
||||
instance.on('error', function (err) {
|
||||
t.is(err.message, 'beep', 'instance errors')
|
||||
|
||||
instance.on('close', function () {
|
||||
t.pass('instance is closed')
|
||||
})
|
||||
|
||||
clone.on('error', function (err3) {
|
||||
t.ok(err === err3, 'clone receives same error')
|
||||
})
|
||||
|
||||
clone.on('close', function () {
|
||||
t.pass('clone is closed')
|
||||
})
|
||||
})
|
||||
|
||||
instance.destroy(new Error('beep'))
|
||||
})
|
||||
|
||||
test('instance destroy destroys all but the source', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
var source = from()
|
||||
var instance = cloneable(source)
|
||||
var clone = instance.clone()
|
||||
|
||||
source.on('close', function () {
|
||||
t.fail('source should not be closed')
|
||||
})
|
||||
|
||||
instance.on('close', function () {
|
||||
t.pass('instance is closed')
|
||||
})
|
||||
|
||||
clone.on('close', function () {
|
||||
t.pass('clone is closed')
|
||||
})
|
||||
|
||||
instance.destroy()
|
||||
})
|
||||
|
||||
test('clone destroy does not affect other clones, cloneable or source', function (t) {
|
||||
t.plan(1)
|
||||
|
||||
var source = from()
|
||||
var instance = cloneable(source)
|
||||
var clone = instance.clone()
|
||||
var other = instance.clone()
|
||||
|
||||
source.on('close', function () {
|
||||
t.fail('source should not be closed')
|
||||
})
|
||||
|
||||
instance.on('close', function () {
|
||||
t.fail('instance should not be closed')
|
||||
})
|
||||
|
||||
other.on('close', function () {
|
||||
t.fail('other clone should not be closed')
|
||||
})
|
||||
|
||||
clone.on('close', function () {
|
||||
t.pass('clone is closed')
|
||||
})
|
||||
|
||||
clone.destroy()
|
||||
})
|
||||
|
||||
test('clone remains readable if other is destroyed', function (t) {
|
||||
t.plan(3)
|
||||
|
||||
var read = false
|
||||
var source = from(function (size, next) {
|
||||
if (read) {
|
||||
this.push(null)
|
||||
} else {
|
||||
read = true
|
||||
this.push('hello')
|
||||
}
|
||||
next()
|
||||
})
|
||||
|
||||
var instance = cloneable(source)
|
||||
var clone = instance.clone()
|
||||
var other = instance.clone()
|
||||
|
||||
instance.pipe(sink.obj(function (chunk, enc, cb) {
|
||||
t.deepEqual(chunk.toString(), 'hello', 'instance chunk matches')
|
||||
cb()
|
||||
}))
|
||||
|
||||
clone.pipe(sink.obj(function (chunk, enc, cb) {
|
||||
t.deepEqual(chunk.toString(), 'hello', 'clone chunk matches')
|
||||
cb()
|
||||
}))
|
||||
|
||||
clone.on('close', function () {
|
||||
t.fail('clone should not be closed')
|
||||
})
|
||||
|
||||
instance.on('close', function () {
|
||||
t.fail('instance should not be closed')
|
||||
})
|
||||
|
||||
other.on('close', function () {
|
||||
t.pass('other is closed')
|
||||
})
|
||||
|
||||
other.destroy()
|
||||
})
|
||||
|
||||
test('clone of clone', function (t) {
|
||||
t.plan(6)
|
||||
|
||||
var read = false
|
||||
var source = from(function (size, next) {
|
||||
if (read) {
|
||||
this.push(null)
|
||||
} else {
|
||||
read = true
|
||||
this.push('hello world')
|
||||
}
|
||||
next()
|
||||
})
|
||||
|
||||
var instance = cloneable(source)
|
||||
t.notOk(read, 'stream not started')
|
||||
|
||||
var cloned = instance.clone()
|
||||
t.notOk(read, 'stream not started')
|
||||
|
||||
var replica = cloned.clone()
|
||||
t.notOk(read, 'stream not started')
|
||||
|
||||
instance.pipe(sink(function (chunk, enc, cb) {
|
||||
t.equal(chunk.toString(), 'hello world', 'chunk matches')
|
||||
cb()
|
||||
}))
|
||||
|
||||
cloned.pipe(sink(function (chunk, enc, cb) {
|
||||
t.equal(chunk.toString(), 'hello world', 'chunk matches')
|
||||
cb()
|
||||
}))
|
||||
|
||||
replica.pipe(sink(function (chunk, enc, cb) {
|
||||
t.equal(chunk.toString(), 'hello world', 'chunk matches')
|
||||
cb()
|
||||
}))
|
||||
})
|
||||
|
||||
test('from vinyl', function (t) {
|
||||
t.plan(3)
|
||||
|
||||
var source = from(['wa', 'dup'])
|
||||
|
||||
var instance = cloneable(source)
|
||||
var clone = instance.clone()
|
||||
|
||||
var data = ''
|
||||
var data2 = ''
|
||||
var ends = 2
|
||||
|
||||
function latch () {
|
||||
if (--ends === 0) {
|
||||
t.equal(data, data2)
|
||||
}
|
||||
}
|
||||
|
||||
instance.on('data', function (chunk) {
|
||||
data += chunk.toString()
|
||||
})
|
||||
|
||||
process.nextTick(function () {
|
||||
t.equal('', data, 'nothing was written yet')
|
||||
t.equal('', data2, 'nothing was written yet')
|
||||
|
||||
clone.on('data', function (chunk) {
|
||||
data2 += chunk.toString()
|
||||
})
|
||||
})
|
||||
|
||||
instance.on('end', latch)
|
||||
clone.on('end', latch)
|
||||
})
|
||||
|
||||
test('waits till all are flowing', function (t) {
|
||||
t.plan(1)
|
||||
|
||||
var source = from(['wa', 'dup'])
|
||||
|
||||
var instance = cloneable(source)
|
||||
|
||||
// we create a clone
|
||||
instance.clone()
|
||||
|
||||
instance.on('data', function (chunk) {
|
||||
t.fail('this should never happen')
|
||||
})
|
||||
|
||||
process.nextTick(function () {
|
||||
t.pass('wait till nextTick')
|
||||
})
|
||||
})
|
||||
|
||||
test('isCloneable', function (t) {
|
||||
t.plan(4)
|
||||
|
||||
var source = from(['hello', ' ', 'world'])
|
||||
t.notOk(cloneable.isCloneable(source), 'a generic readable is not cloneable')
|
||||
|
||||
var instance = cloneable(source)
|
||||
t.ok(cloneable.isCloneable(instance), 'a cloneable is cloneable')
|
||||
|
||||
var clone = instance.clone()
|
||||
t.ok(cloneable.isCloneable(clone), 'a clone is cloneable')
|
||||
|
||||
var cloneClone = clone.clone()
|
||||
t.ok(cloneable.isCloneable(cloneClone), 'a clone of a clone is cloneable')
|
||||
})
|
||||
Reference in New Issue
Block a user