diff options
Diffstat (limited to 'node_modules/stdout-stream')
-rw-r--r-- | node_modules/stdout-stream/.travis.yml | 6 | ||||
-rw-r--r-- | node_modules/stdout-stream/LICENSE | 20 | ||||
-rw-r--r-- | node_modules/stdout-stream/README.md | 45 | ||||
-rw-r--r-- | node_modules/stdout-stream/index.js | 53 | ||||
-rw-r--r-- | node_modules/stdout-stream/package.json | 48 | ||||
-rw-r--r-- | node_modules/stdout-stream/test/fixtures/end.js | 8 | ||||
-rw-r--r-- | node_modules/stdout-stream/test/fixtures/hello-world.js | 4 | ||||
-rw-r--r-- | node_modules/stdout-stream/test/index.js | 33 |
8 files changed, 217 insertions, 0 deletions
diff --git a/node_modules/stdout-stream/.travis.yml b/node_modules/stdout-stream/.travis.yml new file mode 100644 index 0000000..4ff8a05 --- /dev/null +++ b/node_modules/stdout-stream/.travis.yml @@ -0,0 +1,6 @@ +language: node_js +node_js: + - "0.8" + - "0.10" + +script: "npm test" diff --git a/node_modules/stdout-stream/LICENSE b/node_modules/stdout-stream/LICENSE new file mode 100644 index 0000000..4b30ed5 --- /dev/null +++ b/node_modules/stdout-stream/LICENSE @@ -0,0 +1,20 @@ +Copyright 2013 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/node_modules/stdout-stream/README.md b/node_modules/stdout-stream/README.md new file mode 100644 index 0000000..ede4fcd --- /dev/null +++ b/node_modules/stdout-stream/README.md @@ -0,0 +1,45 @@ +# stdout-stream + +Non-blocking stdout stream + + npm install stdout-stream + +[](http://travis-ci.org/mafintosh/stdout-stream) + + + +## Rant + +Try saving this example as `example.js` + +``` js +console.error('start'); +process.stdout.write(new Buffer(1024*1024)); +console.error('end'); +``` + +And run the following program + +``` +node example.js | sleep 1000 +``` + +The program will never print `end` since stdout in node currently is blocking - even when its being piped (!). + +stdout-stream tries to fix this by being a stream that writes to stdout but never blocks + +## Usage + +``` js +var stdout = require('stdout-stream'); + +stdout.write('hello\n'); // write should NEVER block +stdout.write('non-blocking\n') +stdout.write('world\n'); +``` + +`stdout-stream` should behave in the same way as `process.stdout` (i.e. do not end on pipe etc) + +## License + +MIT diff --git a/node_modules/stdout-stream/index.js b/node_modules/stdout-stream/index.js new file mode 100644 index 0000000..a8ab752 --- /dev/null +++ b/node_modules/stdout-stream/index.js @@ -0,0 +1,53 @@ +var fs = require('fs'); +var Writable = require('readable-stream/writable'); + +var exists = function(path) { + try { + return fs.existsSync(path); + } catch (err) { + return false; + } +}; + +module.exports = function() { + var s = new Writable({highWaterMark:0}); + + var cb; + var data; + var tries = 0; + var offset = 0; + + var write = function() { + fs.write(1, data, offset, data.length - offset, null, onwrite); + }; + + var onwrite = function(err, written) { + if (err && err.code === 'EPIPE') return cb() + if (err && err.code === 'EAGAIN' && tries++ < 30) return setTimeout(write, 10); + if (err) return cb(err); + + tries = 0; + if (offset + written >= data.length) return cb(); + + offset += written; + write(); + }; + + s._write = function(_data, enc, _cb) { + offset = 0; + cb = _cb; + data = _data; + write(); + }; + + s._isStdio = true; + s.isTTY = process.stdout.isTTY; + + s.on('finish', function() { + fs.close(1, function(err) { + if (err) s.emit('error', err); + }); + }); + + return s; +}(); diff --git a/node_modules/stdout-stream/package.json b/node_modules/stdout-stream/package.json new file mode 100644 index 0000000..b34166e --- /dev/null +++ b/node_modules/stdout-stream/package.json @@ -0,0 +1,48 @@ +{ + "_from": "stdout-stream@^1.4.0", + "_id": "stdout-stream@1.4.1", + "_inBundle": false, + "_integrity": "sha512-j4emi03KXqJWcIeF8eIXkjMFN1Cmb8gUlDYGeBALLPo5qdyTfA9bOtl8m33lRoC+vFMkP3gl0WsDr6+gzxbbTA==", + "_location": "/stdout-stream", + "_phantomChildren": {}, + "_requested": { + "type": "range", + "registry": true, + "raw": "stdout-stream@^1.4.0", + "name": "stdout-stream", + "escapedName": "stdout-stream", + "rawSpec": "^1.4.0", + "saveSpec": null, + "fetchSpec": "^1.4.0" + }, + "_requiredBy": [ + "/node-sass" + ], + "_resolved": "https://registry.npmjs.org/stdout-stream/-/stdout-stream-1.4.1.tgz", + "_shasum": "5ac174cdd5cd726104aa0c0b2bd83815d8d535de", + "_spec": "stdout-stream@^1.4.0", + "_where": "/home/pruss/Dev/3-minute-website/node_modules/node-sass", + "bugs": { + "url": "https://github.com/mafintosh/stdout-stream/issues" + }, + "bundleDependencies": false, + "dependencies": { + "readable-stream": "^2.0.1" + }, + "deprecated": false, + "description": "Non-blocking stdout stream", + "devDependencies": { + "tape": "~2.12.3" + }, + "homepage": "https://github.com/mafintosh/stdout-stream#readme", + "license": "MIT", + "name": "stdout-stream", + "repository": { + "type": "git", + "url": "git+https://github.com/mafintosh/stdout-stream.git" + }, + "scripts": { + "test": "tape test/index.js" + }, + "version": "1.4.1" +} diff --git a/node_modules/stdout-stream/test/fixtures/end.js b/node_modules/stdout-stream/test/fixtures/end.js new file mode 100644 index 0000000..cdfeba3 --- /dev/null +++ b/node_modules/stdout-stream/test/fixtures/end.js @@ -0,0 +1,8 @@ +var stdout = require('../../'); + +stdout.write('stdout'); +stdout.end(function() { + setTimeout(function() { + process.exit(0); + }, 10); +});
\ No newline at end of file diff --git a/node_modules/stdout-stream/test/fixtures/hello-world.js b/node_modules/stdout-stream/test/fixtures/hello-world.js new file mode 100644 index 0000000..096ee27 --- /dev/null +++ b/node_modules/stdout-stream/test/fixtures/hello-world.js @@ -0,0 +1,4 @@ +var stdout = require('../../'); + +stdout.write('hello\n'); +stdout.write('world\n');
\ No newline at end of file diff --git a/node_modules/stdout-stream/test/index.js b/node_modules/stdout-stream/test/index.js new file mode 100644 index 0000000..d26d079 --- /dev/null +++ b/node_modules/stdout-stream/test/index.js @@ -0,0 +1,33 @@ +var tape = require('tape'); +var proc = require('child_process'); +var path = require('path'); + +tape('print to stdout', function(t) { + proc.exec('"'+process.execPath+'" '+path.join(__dirname,'fixtures','hello-world.js'), function(err, stdout) { + t.ok(!err); + t.same(stdout,'hello\nworld\n'); + t.end(); + }); +}); + +tape('end stdout', function(t) { + var ch = proc.exec('"'+process.execPath+'" '+path.join(__dirname,'fixtures','end.js')); + var buf = []; + var processOnExit = false; + var stdoutOnEnd = false; + + ch.stdout.on('data', function(data) { + buf.push(data); + }); + ch.stdout.on('end', function() { + t.same(Buffer.concat(buf).toString(), 'stdout'); + t.ok(!processOnExit); + stdoutOnEnd = true; + }); + ch.on('exit', function(code) { + processOnExit = true; + t.ok(stdoutOnEnd); + t.same(code, 0); + t.end(); + }); +});
\ No newline at end of file |