summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/through
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/node_modules/through')
-rw-r--r--deps/npm/node_modules/through/.travis.yml5
-rw-r--r--deps/npm/node_modules/through/LICENSE.APACHE215
-rw-r--r--deps/npm/node_modules/through/LICENSE.MIT24
-rw-r--r--deps/npm/node_modules/through/index.js107
-rw-r--r--deps/npm/node_modules/through/package.json69
-rw-r--r--deps/npm/node_modules/through/readme.markdown64
-rw-r--r--deps/npm/node_modules/through/test/async.js28
-rw-r--r--deps/npm/node_modules/through/test/auto-destroy.js29
-rw-r--r--deps/npm/node_modules/through/test/buffering.js71
-rw-r--r--deps/npm/node_modules/through/test/end.js45
-rw-r--r--deps/npm/node_modules/through/test/index.js133
11 files changed, 590 insertions, 0 deletions
diff --git a/deps/npm/node_modules/through/.travis.yml b/deps/npm/node_modules/through/.travis.yml
new file mode 100644
index 0000000000..c693a939df
--- /dev/null
+++ b/deps/npm/node_modules/through/.travis.yml
@@ -0,0 +1,5 @@
+language: node_js
+node_js:
+ - 0.6
+ - 0.8
+ - "0.10"
diff --git a/deps/npm/node_modules/through/LICENSE.APACHE2 b/deps/npm/node_modules/through/LICENSE.APACHE2
new file mode 100644
index 0000000000..6366c04716
--- /dev/null
+++ b/deps/npm/node_modules/through/LICENSE.APACHE2
@@ -0,0 +1,15 @@
+Apache License, Version 2.0
+
+Copyright (c) 2011 Dominic Tarr
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
diff --git a/deps/npm/node_modules/through/LICENSE.MIT b/deps/npm/node_modules/through/LICENSE.MIT
new file mode 100644
index 0000000000..49e7da41fe
--- /dev/null
+++ b/deps/npm/node_modules/through/LICENSE.MIT
@@ -0,0 +1,24 @@
+The MIT License
+
+Copyright (c) 2011 Dominic Tarr
+
+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.
diff --git a/deps/npm/node_modules/through/index.js b/deps/npm/node_modules/through/index.js
new file mode 100644
index 0000000000..9f443ffd2b
--- /dev/null
+++ b/deps/npm/node_modules/through/index.js
@@ -0,0 +1,107 @@
+var Stream = require('stream')
+
+// through
+//
+// a stream that does nothing but re-emit the input.
+// useful for aggregating a series of changing but not ending streams into one stream)
+
+exports = module.exports = through
+through.through = through
+
+//create a readable writable stream.
+
+function through (write, end, opts) {
+ write = write || function (data) { this.queue(data) }
+ end = end || function () { this.queue(null) }
+
+ var ended = false, destroyed = false, buffer = [], _ended = false
+ var stream = new Stream()
+ stream.readable = stream.writable = true
+ stream.paused = false
+
+// stream.autoPause = !(opts && opts.autoPause === false)
+ stream.autoDestroy = !(opts && opts.autoDestroy === false)
+
+ stream.write = function (data) {
+ write.call(this, data)
+ return !stream.paused
+ }
+
+ function drain() {
+ while(buffer.length && !stream.paused) {
+ var data = buffer.shift()
+ if(null === data)
+ return stream.emit('end')
+ else
+ stream.emit('data', data)
+ }
+ }
+
+ stream.queue = stream.push = function (data) {
+// console.error(ended)
+ if(_ended) return stream
+ if(data === null) _ended = true
+ buffer.push(data)
+ drain()
+ return stream
+ }
+
+ //this will be registered as the first 'end' listener
+ //must call destroy next tick, to make sure we're after any
+ //stream piped from here.
+ //this is only a problem if end is not emitted synchronously.
+ //a nicer way to do this is to make sure this is the last listener for 'end'
+
+ stream.on('end', function () {
+ stream.readable = false
+ if(!stream.writable && stream.autoDestroy)
+ process.nextTick(function () {
+ stream.destroy()
+ })
+ })
+
+ function _end () {
+ stream.writable = false
+ end.call(stream)
+ if(!stream.readable && stream.autoDestroy)
+ stream.destroy()
+ }
+
+ stream.end = function (data) {
+ if(ended) return
+ ended = true
+ if(arguments.length) stream.write(data)
+ _end() // will emit or queue
+ return stream
+ }
+
+ stream.destroy = function () {
+ if(destroyed) return
+ destroyed = true
+ ended = true
+ buffer.length = 0
+ stream.writable = stream.readable = false
+ stream.emit('close')
+ return stream
+ }
+
+ stream.pause = function () {
+ if(stream.paused) return
+ stream.paused = true
+ return stream
+ }
+
+ stream.resume = function () {
+ if(stream.paused) {
+ stream.paused = false
+ stream.emit('resume')
+ }
+ drain()
+ //may have become paused again,
+ //as drain emits 'data'.
+ if(!stream.paused)
+ stream.emit('drain')
+ return stream
+ }
+ return stream
+}
diff --git a/deps/npm/node_modules/through/package.json b/deps/npm/node_modules/through/package.json
new file mode 100644
index 0000000000..e1e55755a3
--- /dev/null
+++ b/deps/npm/node_modules/through/package.json
@@ -0,0 +1,69 @@
+{
+ "_from": "through@>=2.2.7 <3",
+ "_id": "through@2.3.8",
+ "_inBundle": false,
+ "_integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=",
+ "_location": "/through",
+ "_phantomChildren": {},
+ "_requested": {
+ "type": "range",
+ "registry": true,
+ "raw": "through@>=2.2.7 <3",
+ "name": "through",
+ "escapedName": "through",
+ "rawSpec": ">=2.2.7 <3",
+ "saveSpec": null,
+ "fetchSpec": ">=2.2.7 <3"
+ },
+ "_requiredBy": [
+ "/JSONStream",
+ "/inquirer"
+ ],
+ "_resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz",
+ "_shasum": "0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5",
+ "_spec": "through@>=2.2.7 <3",
+ "_where": "/Users/rebecca/code/npm/node_modules/JSONStream",
+ "author": {
+ "name": "Dominic Tarr",
+ "email": "dominic.tarr@gmail.com",
+ "url": "dominictarr.com"
+ },
+ "bugs": {
+ "url": "https://github.com/dominictarr/through/issues"
+ },
+ "bundleDependencies": false,
+ "deprecated": false,
+ "description": "simplified stream construction",
+ "devDependencies": {
+ "from": "~0.1.3",
+ "stream-spec": "~0.3.5",
+ "tape": "~2.3.2"
+ },
+ "homepage": "https://github.com/dominictarr/through",
+ "keywords": [
+ "stream",
+ "streams",
+ "user-streams",
+ "pipe"
+ ],
+ "license": "MIT",
+ "main": "index.js",
+ "name": "through",
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/dominictarr/through.git"
+ },
+ "scripts": {
+ "test": "set -e; for t in test/*.js; do node $t; done"
+ },
+ "testling": {
+ "browsers": [
+ "ie/8..latest",
+ "ff/15..latest",
+ "chrome/20..latest",
+ "safari/5.1..latest"
+ ],
+ "files": "test/*.js"
+ },
+ "version": "2.3.8"
+}
diff --git a/deps/npm/node_modules/through/readme.markdown b/deps/npm/node_modules/through/readme.markdown
new file mode 100644
index 0000000000..4939fffe42
--- /dev/null
+++ b/deps/npm/node_modules/through/readme.markdown
@@ -0,0 +1,64 @@
+#through
+
+[![build status](https://secure.travis-ci.org/dominictarr/through.png)](http://travis-ci.org/dominictarr/through)
+[![testling badge](https://ci.testling.com/dominictarr/through.png)](https://ci.testling.com/dominictarr/through)
+
+Easy way to create a `Stream` that is both `readable` and `writable`.
+
+* Pass in optional `write` and `end` methods.
+* `through` takes care of pause/resume logic if you use `this.queue(data)` instead of `this.emit('data', data)`.
+* Use `this.pause()` and `this.resume()` to manage flow.
+* Check `this.paused` to see current flow state. (`write` always returns `!this.paused`).
+
+This function is the basis for most of the synchronous streams in
+[event-stream](http://github.com/dominictarr/event-stream).
+
+``` js
+var through = require('through')
+
+through(function write(data) {
+ this.queue(data) //data *must* not be null
+ },
+ function end () { //optional
+ this.queue(null)
+ })
+```
+
+Or, can also be used _without_ buffering on pause, use `this.emit('data', data)`,
+and this.emit('end')
+
+``` js
+var through = require('through')
+
+through(function write(data) {
+ this.emit('data', data)
+ //this.pause()
+ },
+ function end () { //optional
+ this.emit('end')
+ })
+```
+
+## Extended Options
+
+You will probably not need these 99% of the time.
+
+### autoDestroy=false
+
+By default, `through` emits close when the writable
+and readable side of the stream has ended.
+If that is not desired, set `autoDestroy=false`.
+
+``` js
+var through = require('through')
+
+//like this
+var ts = through(write, end, {autoDestroy: false})
+//or like this
+var ts = through(write, end)
+ts.autoDestroy = false
+```
+
+## License
+
+MIT / Apache2
diff --git a/deps/npm/node_modules/through/test/async.js b/deps/npm/node_modules/through/test/async.js
new file mode 100644
index 0000000000..f6fc95f4ff
--- /dev/null
+++ b/deps/npm/node_modules/through/test/async.js
@@ -0,0 +1,28 @@
+var from = require('from')
+var through = require('../')
+
+var tape = require('tape')
+
+tape('simple async example', function (t) {
+
+ var n = 0, expected = [1,2,3,4,5], actual = []
+ from(expected)
+ .pipe(through(function(data) {
+ this.pause()
+ n ++
+ setTimeout(function(){
+ console.log('pushing data', data)
+ this.push(data)
+ this.resume()
+ }.bind(this), 300)
+ })).pipe(through(function(data) {
+ console.log('pushing data second time', data);
+ this.push(data)
+ })).on('data', function (d) {
+ actual.push(d)
+ }).on('end', function() {
+ t.deepEqual(actual, expected)
+ t.end()
+ })
+
+})
diff --git a/deps/npm/node_modules/through/test/auto-destroy.js b/deps/npm/node_modules/through/test/auto-destroy.js
new file mode 100644
index 0000000000..305fff23d3
--- /dev/null
+++ b/deps/npm/node_modules/through/test/auto-destroy.js
@@ -0,0 +1,29 @@
+var test = require('tape')
+var through = require('../')
+
+// must emit end before close.
+
+test('end before close', function (assert) {
+ var ts = through()
+ ts.autoDestroy = false
+ var ended = false, closed = false
+
+ ts.on('end', function () {
+ assert.ok(!closed)
+ ended = true
+ })
+ ts.on('close', function () {
+ assert.ok(ended)
+ closed = true
+ })
+
+ ts.write(1)
+ ts.write(2)
+ ts.write(3)
+ ts.end()
+ assert.ok(ended)
+ assert.notOk(closed)
+ ts.destroy()
+ assert.ok(closed)
+ assert.end()
+})
diff --git a/deps/npm/node_modules/through/test/buffering.js b/deps/npm/node_modules/through/test/buffering.js
new file mode 100644
index 0000000000..b0084bfc6e
--- /dev/null
+++ b/deps/npm/node_modules/through/test/buffering.js
@@ -0,0 +1,71 @@
+var test = require('tape')
+var through = require('../')
+
+// must emit end before close.
+
+test('buffering', function(assert) {
+ var ts = through(function (data) {
+ this.queue(data)
+ }, function () {
+ this.queue(null)
+ })
+
+ var ended = false, actual = []
+
+ ts.on('data', actual.push.bind(actual))
+ ts.on('end', function () {
+ ended = true
+ })
+
+ ts.write(1)
+ ts.write(2)
+ ts.write(3)
+ assert.deepEqual(actual, [1, 2, 3])
+ ts.pause()
+ ts.write(4)
+ ts.write(5)
+ ts.write(6)
+ assert.deepEqual(actual, [1, 2, 3])
+ ts.resume()
+ assert.deepEqual(actual, [1, 2, 3, 4, 5, 6])
+ ts.pause()
+ ts.end()
+ assert.ok(!ended)
+ ts.resume()
+ assert.ok(ended)
+ assert.end()
+})
+
+test('buffering has data in queue, when ends', function (assert) {
+
+ /*
+ * If stream ends while paused with data in the queue,
+ * stream should still emit end after all data is written
+ * on resume.
+ */
+
+ var ts = through(function (data) {
+ this.queue(data)
+ }, function () {
+ this.queue(null)
+ })
+
+ var ended = false, actual = []
+
+ ts.on('data', actual.push.bind(actual))
+ ts.on('end', function () {
+ ended = true
+ })
+
+ ts.pause()
+ ts.write(1)
+ ts.write(2)
+ ts.write(3)
+ ts.end()
+ assert.deepEqual(actual, [], 'no data written yet, still paused')
+ assert.ok(!ended, 'end not emitted yet, still paused')
+ ts.resume()
+ assert.deepEqual(actual, [1, 2, 3], 'resumed, all data should be delivered')
+ assert.ok(ended, 'end should be emitted once all data was delivered')
+ assert.end();
+})
diff --git a/deps/npm/node_modules/through/test/end.js b/deps/npm/node_modules/through/test/end.js
new file mode 100644
index 0000000000..fa113f58e0
--- /dev/null
+++ b/deps/npm/node_modules/through/test/end.js
@@ -0,0 +1,45 @@
+var test = require('tape')
+var through = require('../')
+
+// must emit end before close.
+
+test('end before close', function (assert) {
+ var ts = through()
+ var ended = false, closed = false
+
+ ts.on('end', function () {
+ assert.ok(!closed)
+ ended = true
+ })
+ ts.on('close', function () {
+ assert.ok(ended)
+ closed = true
+ })
+
+ ts.write(1)
+ ts.write(2)
+ ts.write(3)
+ ts.end()
+ assert.ok(ended)
+ assert.ok(closed)
+ assert.end()
+})
+
+test('end only once', function (t) {
+
+ var ts = through()
+ var ended = false, closed = false
+
+ ts.on('end', function () {
+ t.equal(ended, false)
+ ended = true
+ })
+
+ ts.queue(null)
+ ts.queue(null)
+ ts.queue(null)
+
+ ts.resume()
+
+ t.end()
+})
diff --git a/deps/npm/node_modules/through/test/index.js b/deps/npm/node_modules/through/test/index.js
new file mode 100644
index 0000000000..1d9523f40e
--- /dev/null
+++ b/deps/npm/node_modules/through/test/index.js
@@ -0,0 +1,133 @@
+
+var test = require('tape')
+var spec = require('stream-spec')
+var through = require('../')
+
+/*
+ I'm using these two functions, and not streams and pipe
+ so there is less to break. if this test fails it must be
+ the implementation of _through_
+*/
+
+function write(array, stream) {
+ array = array.slice()
+ function next() {
+ while(array.length)
+ if(stream.write(array.shift()) === false)
+ return stream.once('drain', next)
+
+ stream.end()
+ }
+
+ next()
+}
+
+function read(stream, callback) {
+ var actual = []
+ stream.on('data', function (data) {
+ actual.push(data)
+ })
+ stream.once('end', function () {
+ callback(null, actual)
+ })
+ stream.once('error', function (err) {
+ callback(err)
+ })
+}
+
+test('simple defaults', function(assert) {
+
+ var l = 1000
+ , expected = []
+
+ while(l--) expected.push(l * Math.random())
+
+ var t = through()
+ var s = spec(t).through().pausable()
+
+ read(t, function (err, actual) {
+ assert.ifError(err)
+ assert.deepEqual(actual, expected)
+ assert.end()
+ })
+
+ t.on('close', s.validate)
+
+ write(expected, t)
+});
+
+test('simple functions', function(assert) {
+
+ var l = 1000
+ , expected = []
+
+ while(l--) expected.push(l * Math.random())
+
+ var t = through(function (data) {
+ this.emit('data', data*2)
+ })
+ var s = spec(t).through().pausable()
+
+
+ read(t, function (err, actual) {
+ assert.ifError(err)
+ assert.deepEqual(actual, expected.map(function (data) {
+ return data*2
+ }))
+ assert.end()
+ })
+
+ t.on('close', s.validate)
+
+ write(expected, t)
+})
+
+test('pauses', function(assert) {
+
+ var l = 1000
+ , expected = []
+
+ while(l--) expected.push(l) //Math.random())
+
+ var t = through()
+
+ var s = spec(t)
+ .through()
+ .pausable()
+
+ t.on('data', function () {
+ if(Math.random() > 0.1) return
+ t.pause()
+ process.nextTick(function () {
+ t.resume()
+ })
+ })
+
+ read(t, function (err, actual) {
+ assert.ifError(err)
+ assert.deepEqual(actual, expected)
+ })
+
+ t.on('close', function () {
+ s.validate()
+ assert.end()
+ })
+
+ write(expected, t)
+})
+
+test('does not soft-end on `undefined`', function(assert) {
+ var stream = through()
+ , count = 0
+
+ stream.on('data', function (data) {
+ count++
+ })
+
+ stream.write(undefined)
+ stream.write(undefined)
+
+ assert.equal(count, 2)
+
+ assert.end()
+})