diff options
Diffstat (limited to 'deps/npm/node_modules/mississippi/node_modules/flush-write-stream')
7 files changed, 295 insertions, 0 deletions
diff --git a/deps/npm/node_modules/mississippi/node_modules/flush-write-stream/.npmignore b/deps/npm/node_modules/mississippi/node_modules/flush-write-stream/.npmignore new file mode 100644 index 0000000000..3c3629e647 --- /dev/null +++ b/deps/npm/node_modules/mississippi/node_modules/flush-write-stream/.npmignore @@ -0,0 +1 @@ +node_modules diff --git a/deps/npm/node_modules/mississippi/node_modules/flush-write-stream/.travis.yml b/deps/npm/node_modules/mississippi/node_modules/flush-write-stream/.travis.yml new file mode 100644 index 0000000000..c042821703 --- /dev/null +++ b/deps/npm/node_modules/mississippi/node_modules/flush-write-stream/.travis.yml @@ -0,0 +1,6 @@ +language: node_js +node_js: + - '0.10' + - '0.12' + - '4.0' + - '5.0' diff --git a/deps/npm/node_modules/mississippi/node_modules/flush-write-stream/LICENSE b/deps/npm/node_modules/mississippi/node_modules/flush-write-stream/LICENSE new file mode 100644 index 0000000000..66a4d2a149 --- /dev/null +++ b/deps/npm/node_modules/mississippi/node_modules/flush-write-stream/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2015 Mathias Buus + +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/mississippi/node_modules/flush-write-stream/README.md b/deps/npm/node_modules/mississippi/node_modules/flush-write-stream/README.md new file mode 100644 index 0000000000..7ea7b699b8 --- /dev/null +++ b/deps/npm/node_modules/mississippi/node_modules/flush-write-stream/README.md @@ -0,0 +1,59 @@ +# flush-write-stream + +A write stream constructor that supports a flush function that is called before `finish` is emitted + +``` +npm install flush-write-stream +``` + +[![build status](http://img.shields.io/travis/mafintosh/flush-write-stream.svg?style=flat)](http://travis-ci.org/mafintosh/flush-write-stream) + +## Usage + +``` js +var writer = require('flush-write-stream') + +var ws = writer(write, flush) + +ws.on('finish', function () { + console.log('finished') +}) + +ws.write('hello') +ws.write('world') +ws.end() + +function write (data, enc, cb) { + // i am your normal ._write method + console.log('writing', data.toString()) + cb() +} + +function flush (cb) { + // i am called before finish is emitted + setTimeout(cb, 1000) // wait 1 sec +} +``` + +If you run the above it will produce the following output + +``` +writing hello +writing world +(nothing happens for 1 sec) +finished +``` + +## API + +#### `var ws = writer([options], write, [flush])` + +Create a new writable stream. Options are forwarded to the stream constructor. + +#### `var ws = writer.obj([options], write, [flush])` + +Same as the above except `objectMode` is set to `true` per default. + +## License + +MIT diff --git a/deps/npm/node_modules/mississippi/node_modules/flush-write-stream/index.js b/deps/npm/node_modules/mississippi/node_modules/flush-write-stream/index.js new file mode 100644 index 0000000000..d7715734b4 --- /dev/null +++ b/deps/npm/node_modules/mississippi/node_modules/flush-write-stream/index.js @@ -0,0 +1,52 @@ +var stream = require('readable-stream') +var util = require('util') + +var SIGNAL_FLUSH = new Buffer([0]) + +module.exports = WriteStream + +function WriteStream (opts, write, flush) { + if (!(this instanceof WriteStream)) return new WriteStream(opts, write, flush) + + if (typeof opts === 'function') { + flush = write + write = opts + opts = {} + } + + stream.Writable.call(this, opts) + + this.destroyed = false + this._worker = write || null + this._flush = flush || null +} + +util.inherits(WriteStream, stream.Writable) + +WriteStream.obj = function (opts, worker, flush) { + if (typeof opts === 'function') return WriteStream.obj(null, opts, worker) + if (!opts) opts = {} + opts.objectMode = true + return new WriteStream(opts, worker, flush) +} + +WriteStream.prototype._write = function (data, enc, cb) { + if (SIGNAL_FLUSH === data) this._flush(cb) + else this._worker(data, enc, cb) +} + +WriteStream.prototype.end = function (data, enc, cb) { + if (!this._flush) return stream.Writable.prototype.end.apply(this, arguments) + if (typeof data === 'function') return this.end(null, null, data) + if (typeof enc === 'function') return this.end(data, null, enc) + if (data) this.write(data) + if (!this._writableState.ending) this.write(SIGNAL_FLUSH) + return stream.Writable.prototype.end.call(this, cb) +} + +WriteStream.prototype.destroy = function (err) { + if (this.destroyed) return + this.destroyed = true + if (err) this.emit('error') + this.emit('close') +} diff --git a/deps/npm/node_modules/mississippi/node_modules/flush-write-stream/package.json b/deps/npm/node_modules/mississippi/node_modules/flush-write-stream/package.json new file mode 100644 index 0000000000..a73eaeb36e --- /dev/null +++ b/deps/npm/node_modules/mississippi/node_modules/flush-write-stream/package.json @@ -0,0 +1,84 @@ +{ + "_args": [ + [ + { + "raw": "flush-write-stream@^1.0.0", + "scope": null, + "escapedName": "flush-write-stream", + "name": "flush-write-stream", + "rawSpec": "^1.0.0", + "spec": ">=1.0.0 <2.0.0", + "type": "range" + }, + "/Users/zkat/Documents/code/npm/node_modules/mississippi" + ] + ], + "_from": "flush-write-stream@>=1.0.0 <2.0.0", + "_id": "flush-write-stream@1.0.0", + "_inCache": true, + "_location": "/mississippi/flush-write-stream", + "_nodeVersion": "4.1.1", + "_npmUser": { + "name": "mafintosh", + "email": "mathiasbuus@gmail.com" + }, + "_npmVersion": "2.14.4", + "_phantomChildren": {}, + "_requested": { + "raw": "flush-write-stream@^1.0.0", + "scope": null, + "escapedName": "flush-write-stream", + "name": "flush-write-stream", + "rawSpec": "^1.0.0", + "spec": ">=1.0.0 <2.0.0", + "type": "range" + }, + "_requiredBy": [ + "/mississippi" + ], + "_resolved": "https://registry.npmjs.org/flush-write-stream/-/flush-write-stream-1.0.0.tgz", + "_shasum": "cc4fc24f4b4c973f80027f27cc095841639965a7", + "_shrinkwrap": null, + "_spec": "flush-write-stream@^1.0.0", + "_where": "/Users/zkat/Documents/code/npm/node_modules/mississippi", + "author": { + "name": "Mathias Buus", + "url": "@mafintosh" + }, + "bugs": { + "url": "https://github.com/mafintosh/flush-write-stream/issues" + }, + "dependencies": { + "readable-stream": "^2.0.4" + }, + "description": "A write stream constructor that supports a flush function that is called before finish is emitted", + "devDependencies": { + "tape": "^4.2.2" + }, + "directories": {}, + "dist": { + "shasum": "cc4fc24f4b4c973f80027f27cc095841639965a7", + "tarball": "https://registry.npmjs.org/flush-write-stream/-/flush-write-stream-1.0.0.tgz" + }, + "gitHead": "50e81d8eeee8a9666c7d5105775a6c89b7ae9dfa", + "homepage": "https://github.com/mafintosh/flush-write-stream", + "license": "MIT", + "main": "index.js", + "maintainers": [ + { + "name": "mafintosh", + "email": "mathiasbuus@gmail.com" + } + ], + "name": "flush-write-stream", + "optionalDependencies": {}, + "readme": "ERROR: No README data found!", + "repository": { + "type": "git", + "url": "git+https://github.com/mafintosh/flush-write-stream.git" + }, + "scripts": { + "test": "tape test.js" + }, + "version": "1.0.0" +} diff --git a/deps/npm/node_modules/mississippi/node_modules/flush-write-stream/test.js b/deps/npm/node_modules/mississippi/node_modules/flush-write-stream/test.js new file mode 100644 index 0000000000..7383acede6 --- /dev/null +++ b/deps/npm/node_modules/mississippi/node_modules/flush-write-stream/test.js @@ -0,0 +1,72 @@ +var tape = require('tape') +var writer = require('./') + +tape('is a write stream', function (t) { + var expected = ['hello', 'world', 'verden'] + var ws = writer.obj(write) + + ws.write('hello') + ws.write('world') + ws.write('verden') + ws.end(function () { + t.same(expected.length, 0) + t.end() + }) + + function write (data, enc, cb) { + t.same(data, expected.shift()) + cb() + } +}) + +tape('is flushable', function (t) { + var expected = ['hello', 'world', 'verden'] + var flushed = false + + var ws = writer.obj(write, flush) + + ws.write('hello') + ws.write('world') + ws.write('verden') + ws.end(function () { + t.same(expected.length, 0) + t.ok(flushed, 'was flushed') + t.end() + }) + + function write (data, enc, cb) { + t.same(data, expected.shift()) + cb() + } + + function flush (cb) { + flushed = true + process.nextTick(cb) + } +}) + +tape('can pass options', function (t) { + var expected = ['hello', 'world', 'verden'] + var flushed = false + + var ws = writer({objectMode: true}, write, flush) + + ws.write('hello') + ws.write('world') + ws.write('verden') + ws.end(function () { + t.same(expected.length, 0) + t.ok(flushed, 'was flushed') + t.end() + }) + + function write (data, enc, cb) { + t.same(data, expected.shift()) + cb() + } + + function flush (cb) { + flushed = true + process.nextTick(cb) + } +}) |