$
This commit is contained in:
6
node_modules/stdout-stream/.travis.yml
generated
vendored
Normal file
6
node_modules/stdout-stream/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "0.8"
|
||||
- "0.10"
|
||||
|
||||
script: "npm test"
|
20
node_modules/stdout-stream/LICENSE
generated
vendored
Normal file
20
node_modules/stdout-stream/LICENSE
generated
vendored
Normal file
@@ -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.
|
45
node_modules/stdout-stream/README.md
generated
vendored
Normal file
45
node_modules/stdout-stream/README.md
generated
vendored
Normal file
@@ -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
|
53
node_modules/stdout-stream/index.js
generated
vendored
Normal file
53
node_modules/stdout-stream/index.js
generated
vendored
Normal file
@@ -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;
|
||||
}();
|
16
node_modules/stdout-stream/package.json
generated
vendored
Normal file
16
node_modules/stdout-stream/package.json
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "stdout-stream",
|
||||
"description": "Non-blocking stdout stream",
|
||||
"version": "1.4.1",
|
||||
"repository": "mafintosh/stdout-stream",
|
||||
"devDependencies": {
|
||||
"tape": "~2.12.3"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "tape test/index.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"readable-stream": "^2.0.1"
|
||||
},
|
||||
"license": "MIT"
|
||||
}
|
8
node_modules/stdout-stream/test/fixtures/end.js
generated
vendored
Normal file
8
node_modules/stdout-stream/test/fixtures/end.js
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
var stdout = require('../../');
|
||||
|
||||
stdout.write('stdout');
|
||||
stdout.end(function() {
|
||||
setTimeout(function() {
|
||||
process.exit(0);
|
||||
}, 10);
|
||||
});
|
4
node_modules/stdout-stream/test/fixtures/hello-world.js
generated
vendored
Normal file
4
node_modules/stdout-stream/test/fixtures/hello-world.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
var stdout = require('../../');
|
||||
|
||||
stdout.write('hello\n');
|
||||
stdout.write('world\n');
|
33
node_modules/stdout-stream/test/index.js
generated
vendored
Normal file
33
node_modules/stdout-stream/test/index.js
generated
vendored
Normal file
@@ -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();
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user