Initial commit
This commit is contained in:
59
node_modules/through2/.jshintrc
generated
vendored
Normal file
59
node_modules/through2/.jshintrc
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
{
|
||||
"predef": [ ]
|
||||
, "bitwise": false
|
||||
, "camelcase": false
|
||||
, "curly": false
|
||||
, "eqeqeq": false
|
||||
, "forin": false
|
||||
, "immed": false
|
||||
, "latedef": false
|
||||
, "noarg": true
|
||||
, "noempty": true
|
||||
, "nonew": true
|
||||
, "plusplus": false
|
||||
, "quotmark": true
|
||||
, "regexp": false
|
||||
, "undef": true
|
||||
, "unused": true
|
||||
, "strict": false
|
||||
, "trailing": true
|
||||
, "maxlen": 120
|
||||
, "asi": true
|
||||
, "boss": true
|
||||
, "debug": true
|
||||
, "eqnull": true
|
||||
, "esnext": true
|
||||
, "evil": true
|
||||
, "expr": true
|
||||
, "funcscope": false
|
||||
, "globalstrict": false
|
||||
, "iterator": false
|
||||
, "lastsemic": true
|
||||
, "laxbreak": true
|
||||
, "laxcomma": true
|
||||
, "loopfunc": true
|
||||
, "multistr": false
|
||||
, "onecase": false
|
||||
, "proto": false
|
||||
, "regexdash": false
|
||||
, "scripturl": true
|
||||
, "smarttabs": false
|
||||
, "shadow": false
|
||||
, "sub": true
|
||||
, "supernew": false
|
||||
, "validthis": true
|
||||
, "browser": true
|
||||
, "couch": false
|
||||
, "devel": false
|
||||
, "dojo": false
|
||||
, "mootools": false
|
||||
, "node": true
|
||||
, "nonstandard": true
|
||||
, "prototypejs": false
|
||||
, "rhino": false
|
||||
, "worker": true
|
||||
, "wsh": false
|
||||
, "nomen": false
|
||||
, "onevar": false
|
||||
, "passfail": false
|
||||
}
|
||||
1
node_modules/through2/.npmignore
generated
vendored
Normal file
1
node_modules/through2/.npmignore
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
node_modules
|
||||
12
node_modules/through2/.travis.yml
generated
vendored
Normal file
12
node_modules/through2/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "0.8"
|
||||
- "0.10"
|
||||
- "0.11"
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
notifications:
|
||||
email:
|
||||
- rod@vagg.org
|
||||
script: npm test
|
||||
39
node_modules/through2/LICENSE
generated
vendored
Normal file
39
node_modules/through2/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
Copyright 2013, Rod Vagg (the "Original Author")
|
||||
All rights reserved.
|
||||
|
||||
MIT +no-false-attribs License
|
||||
|
||||
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.
|
||||
|
||||
Distributions of all or part of the Software intended to be used
|
||||
by the recipients as they would use the unmodified Software,
|
||||
containing modifications that substantially alter, remove, or
|
||||
disable functionality of the Software, outside of the documented
|
||||
configuration mechanisms provided by the Software, shall be
|
||||
modified such that the Original Author's bug reporting email
|
||||
addresses and urls are either replaced with the contact information
|
||||
of the parties responsible for the changes, or removed entirely.
|
||||
|
||||
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.
|
||||
|
||||
|
||||
Except where noted, this license applies to any and all software
|
||||
programs and associated documentation files created by the
|
||||
Original Author, when distributed with the Software.
|
||||
336
node_modules/through2/LICENSE.html
generated
vendored
Normal file
336
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>
|
||||
107
node_modules/through2/README.md
generated
vendored
Normal file
107
node_modules/through2/README.md
generated
vendored
Normal file
@@ -0,0 +1,107 @@
|
||||
# through2
|
||||
|
||||
[](http://travis-ci.org/rvagg/through2)
|
||||
|
||||
[](https://nodei.co/npm/through2/)
|
||||
|
||||
[](https://david-dm.org/rvagg/through2/)
|
||||
[](https://david-dm.org/rvagg/through2#info=devDependencies/)
|
||||
|
||||
**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) { ... })`.
|
||||
|
||||
```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'))
|
||||
```
|
||||
|
||||
Or object streams:
|
||||
|
||||
```js
|
||||
var all = []
|
||||
fs.createReadStream('data.csv')
|
||||
.pipe(csv2())
|
||||
.pipe(through2({ objectMode: true }, 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)
|
||||
})
|
||||
```
|
||||
|
||||
## 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.
|
||||
|
||||
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) {
|
||||
this.push(new Buffer('wut?'))
|
||||
cb()
|
||||
})
|
||||
.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.
|
||||
|
||||
If you **do not provide a `transformFunction`** then you will get a simple 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.
|
||||
|
||||
<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})
|
||||
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
**through2** is Copyright (c) 2013 Rod Vagg [@rvagg](https://twitter.com/rvagg) and licenced under the MIT licence. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE file for more details.
|
||||
22
node_modules/through2/package.json
generated
vendored
Normal file
22
node_modules/through2/package.json
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "through2",
|
||||
"version": "2.0.3",
|
||||
"description": "A tiny wrapper around Node streams2 Transform to avoid explicit subclassing noise",
|
||||
"main": "through2.js",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/rvagg/through2.git"
|
||||
},
|
||||
"author": "Rod Vagg <r@va.gg> (https://github.com/rvagg)",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"readable-stream": "^2.1.5",
|
||||
"xtend": "~4.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"bl": "~1.1.2",
|
||||
"faucet": "0.0.1",
|
||||
"stream-spigot": "~3.0.5",
|
||||
"tape": "~4.6.2"
|
||||
}
|
||||
}
|
||||
314
node_modules/through2/test.js
generated
vendored
Normal file
314
node_modules/through2/test.js
generated
vendored
Normal file
@@ -0,0 +1,314 @@
|
||||
const test = require('tape')
|
||||
, through2 = require('./')
|
||||
, crypto = require('crypto')
|
||||
, bl = require('bl')
|
||||
, spigot = require('stream-spigot')
|
||||
|
||||
test('plain through', function (t) {
|
||||
var th2 = through2(function (chunk, enc, callback) {
|
||||
if (!this._i)
|
||||
this._i = 97 // 'a'
|
||||
else
|
||||
this._i++
|
||||
var b = new Buffer(chunk.length)
|
||||
for (var i = 0; i < chunk.length; i++)
|
||||
b[i] = this._i
|
||||
this.push(b)
|
||||
callback()
|
||||
})
|
||||
|
||||
th2.pipe(bl(function (err, b) {
|
||||
var s = b.toString('ascii')
|
||||
t.equal('aaaaaaaaaabbbbbcccccccccc', s, 'got transformed string')
|
||||
t.end()
|
||||
}))
|
||||
|
||||
th2.write(crypto.randomBytes(10))
|
||||
th2.write(crypto.randomBytes(5))
|
||||
th2.write(crypto.randomBytes(10))
|
||||
th2.end()
|
||||
})
|
||||
|
||||
test('pipeable through', function (t) {
|
||||
var th2 = through2(function (chunk, enc, callback) {
|
||||
if (!this._i)
|
||||
this._i = 97 // 'a'
|
||||
else
|
||||
this._i++
|
||||
var b = new Buffer(chunk.length)
|
||||
for (var i = 0; i < chunk.length; i++)
|
||||
b[i] = this._i
|
||||
this.push(b)
|
||||
callback()
|
||||
})
|
||||
|
||||
th2.pipe(bl(function (err, b) {
|
||||
var s = b.toString('ascii')
|
||||
// bl() acts like a proper streams2 stream and passes as much as it's
|
||||
// asked for, so we really only get one write with such a small amount
|
||||
// of data
|
||||
t.equal(s, 'aaaaaaaaaaaaaaaaaaaaaaaaa', 'got transformed string')
|
||||
t.end()
|
||||
}))
|
||||
|
||||
var bufs = bl()
|
||||
bufs.append(crypto.randomBytes(10))
|
||||
bufs.append(crypto.randomBytes(5))
|
||||
bufs.append(crypto.randomBytes(10))
|
||||
bufs.pipe(th2)
|
||||
})
|
||||
|
||||
test('object through', function (t) {
|
||||
t.plan(3)
|
||||
|
||||
var th2 = through2({ objectMode: true}, function (chunk, enc, callback) {
|
||||
this.push({ out: chunk.in + 1 })
|
||||
callback()
|
||||
})
|
||||
|
||||
var e = 0
|
||||
th2.on('data', function (o) {
|
||||
t.deepEqual(o, { out: e === 0 ? 102 : e == 1 ? 203 : -99 }, 'got transformed object')
|
||||
e++
|
||||
})
|
||||
|
||||
th2.write({ in: 101 })
|
||||
th2.write({ in: 202 })
|
||||
th2.write({ in: -100 })
|
||||
th2.end()
|
||||
})
|
||||
|
||||
test('flushing through', function (t) {
|
||||
var th2 = through2(function (chunk, enc, callback) {
|
||||
if (!this._i)
|
||||
this._i = 97 // 'a'
|
||||
else
|
||||
this._i++
|
||||
var b = new Buffer(chunk.length)
|
||||
for (var i = 0; i < chunk.length; i++)
|
||||
b[i] = this._i
|
||||
this.push(b)
|
||||
callback()
|
||||
}, function (callback) {
|
||||
this.push(new Buffer([ 101, 110, 100 ]))
|
||||
callback()
|
||||
})
|
||||
|
||||
th2.pipe(bl(function (err, b) {
|
||||
var s = b.toString('ascii')
|
||||
t.equal(s, 'aaaaaaaaaabbbbbccccccccccend', 'got transformed string')
|
||||
t.end()
|
||||
}))
|
||||
|
||||
th2.write(crypto.randomBytes(10))
|
||||
th2.write(crypto.randomBytes(5))
|
||||
th2.write(crypto.randomBytes(10))
|
||||
th2.end()
|
||||
})
|
||||
|
||||
test('plain through ctor', function (t) {
|
||||
var Th2 = through2.ctor(function (chunk, enc, callback) {
|
||||
if (!this._i)
|
||||
this._i = 97 // 'a'
|
||||
else
|
||||
this._i++
|
||||
var b = new Buffer(chunk.length)
|
||||
for (var i = 0; i < chunk.length; i++)
|
||||
b[i] = this._i
|
||||
this.push(b)
|
||||
callback()
|
||||
})
|
||||
|
||||
var th2 = new Th2()
|
||||
|
||||
th2.pipe(bl(function (err, b) {
|
||||
var s = b.toString('ascii')
|
||||
t.equal('aaaaaaaaaabbbbbcccccccccc', s, 'got transformed string')
|
||||
t.end()
|
||||
}))
|
||||
|
||||
th2.write(crypto.randomBytes(10))
|
||||
th2.write(crypto.randomBytes(5))
|
||||
th2.write(crypto.randomBytes(10))
|
||||
th2.end()
|
||||
})
|
||||
|
||||
test('reuse through ctor', function (t) {
|
||||
t.plan(4)
|
||||
|
||||
var Th2 = through2.ctor(function (chunk, enc, callback) {
|
||||
if (!this._i) {
|
||||
t.ok(1, 'did not contain previous instance data (this._i)')
|
||||
this._i = 97 // 'a'
|
||||
} else
|
||||
this._i++
|
||||
var b = new Buffer(chunk.length)
|
||||
for (var i = 0; i < chunk.length; i++)
|
||||
b[i] = this._i
|
||||
this.push(b)
|
||||
callback()
|
||||
})
|
||||
|
||||
var th2 = Th2()
|
||||
|
||||
th2.pipe(bl(function (err, b) {
|
||||
var s = b.toString('ascii')
|
||||
t.equal('aaaaaaaaaabbbbbcccccccccc', s, 'got transformed string')
|
||||
|
||||
var newInstance = Th2()
|
||||
newInstance.pipe(bl(function (err, b) {
|
||||
var s = b.toString('ascii')
|
||||
t.equal('aaaaaaabbbbccccccc', s, 'got transformed string')
|
||||
}))
|
||||
|
||||
newInstance.write(crypto.randomBytes(7))
|
||||
newInstance.write(crypto.randomBytes(4))
|
||||
newInstance.write(crypto.randomBytes(7))
|
||||
newInstance.end()
|
||||
}))
|
||||
|
||||
th2.write(crypto.randomBytes(10))
|
||||
th2.write(crypto.randomBytes(5))
|
||||
th2.write(crypto.randomBytes(10))
|
||||
th2.end()
|
||||
})
|
||||
|
||||
test('object through ctor', function (t) {
|
||||
t.plan(3)
|
||||
|
||||
var Th2 = through2.ctor({ objectMode: true}, function (chunk, enc, callback) {
|
||||
this.push({ out: chunk.in + 1 })
|
||||
callback()
|
||||
})
|
||||
|
||||
var th2 = new Th2()
|
||||
|
||||
var e = 0
|
||||
th2.on('data', function (o) {
|
||||
t.deepEqual(o, { out: e === 0 ? 102 : e == 1 ? 203 : -99 }, 'got transformed object')
|
||||
e++
|
||||
})
|
||||
|
||||
th2.write({ in: 101 })
|
||||
th2.write({ in: 202 })
|
||||
th2.write({ in: -100 })
|
||||
th2.end()
|
||||
})
|
||||
|
||||
test('pipeable object through ctor', function (t) {
|
||||
t.plan(4)
|
||||
|
||||
var Th2 = through2.ctor({ objectMode: true}, function (record, enc, callback) {
|
||||
if (record.temp != null && record.unit == 'F') {
|
||||
record.temp = ( ( record.temp - 32 ) * 5 ) / 9
|
||||
record.unit = 'C'
|
||||
}
|
||||
this.push(record)
|
||||
callback()
|
||||
})
|
||||
|
||||
var th2 = Th2()
|
||||
|
||||
var expect = [-19, -40, 100, 22]
|
||||
th2.on('data', function (o) {
|
||||
t.deepEqual(o, { temp: expect.shift(), unit: 'C' }, 'got transformed object')
|
||||
})
|
||||
|
||||
spigot({objectMode: true}, [
|
||||
{temp: -2.2, unit: 'F'},
|
||||
{temp: -40, unit: 'F'},
|
||||
{temp: 212, unit: 'F'},
|
||||
{temp: 22, unit: 'C'}
|
||||
]).pipe(th2)
|
||||
})
|
||||
|
||||
test('object through ctor override', function (t) {
|
||||
t.plan(3)
|
||||
|
||||
var Th2 = through2.ctor(function (chunk, enc, callback) {
|
||||
this.push({ out: chunk.in + 1 })
|
||||
callback()
|
||||
})
|
||||
|
||||
var th2 = Th2({objectMode: true})
|
||||
|
||||
var e = 0
|
||||
th2.on('data', function (o) {
|
||||
t.deepEqual(o, { out: e === 0 ? 102 : e == 1 ? 203 : -99 }, 'got transformed object')
|
||||
e++
|
||||
})
|
||||
|
||||
th2.write({ in: 101 })
|
||||
th2.write({ in: 202 })
|
||||
th2.write({ in: -100 })
|
||||
th2.end()
|
||||
})
|
||||
|
||||
test('object settings available in transform', function (t) {
|
||||
t.plan(6)
|
||||
|
||||
var Th2 = through2.ctor({objectMode: true, peek: true}, function (chunk, enc, callback) {
|
||||
t.ok(this.options.peek, "reading options from inside _transform")
|
||||
this.push({ out: chunk.in + 1 })
|
||||
callback()
|
||||
})
|
||||
|
||||
var th2 = Th2()
|
||||
|
||||
var e = 0
|
||||
th2.on('data', function (o) {
|
||||
t.deepEqual(o, { out: e === 0 ? 102 : e == 1 ? 203 : -99 }, 'got transformed object')
|
||||
e++
|
||||
})
|
||||
|
||||
th2.write({ in: 101 })
|
||||
th2.write({ in: 202 })
|
||||
th2.write({ in: -100 })
|
||||
th2.end()
|
||||
})
|
||||
|
||||
test('object settings available in transform override', function (t) {
|
||||
t.plan(6)
|
||||
|
||||
var Th2 = through2.ctor(function (chunk, enc, callback) {
|
||||
t.ok(this.options.peek, "reading options from inside _transform")
|
||||
this.push({ out: chunk.in + 1 })
|
||||
callback()
|
||||
})
|
||||
|
||||
var th2 = Th2({objectMode: true, peek: true})
|
||||
|
||||
var e = 0
|
||||
th2.on('data', function (o) {
|
||||
t.deepEqual(o, { out: e === 0 ? 102 : e == 1 ? 203 : -99 }, 'got transformed object')
|
||||
e++
|
||||
})
|
||||
|
||||
th2.write({ in: 101 })
|
||||
th2.write({ in: 202 })
|
||||
th2.write({ in: -100 })
|
||||
th2.end()
|
||||
})
|
||||
|
||||
test('object override extends options', function (t) {
|
||||
t.plan(6)
|
||||
|
||||
var Th2 = through2.ctor({objectMode: true}, function (chunk, enc, callback) {
|
||||
t.ok(this.options.peek, "reading options from inside _transform")
|
||||
this.push({ out: chunk.in + 1 })
|
||||
callback()
|
||||
})
|
||||
|
||||
var th2 = Th2({peek: true})
|
||||
|
||||
var e = 0
|
||||
th2.on('data', function (o) {
|
||||
t.deepEqual(o, { out: e === 0 ? 102 : e == 1 ? 203 : -99 }, 'got transformed object')
|
||||
e++
|
||||
})
|
||||
|
||||
th2.write({ in: 101 })
|
||||
th2.write({ in: 202 })
|
||||
th2.write({ in: -100 })
|
||||
th2.end()
|
||||
})
|
||||
96
node_modules/through2/through2.js
generated
vendored
Normal file
96
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
|
||||
})
|
||||
Reference in New Issue
Block a user