Pushing changes
This commit is contained in:
17
node_modules/streamroller/.jshintrc
generated
vendored
Normal file
17
node_modules/streamroller/.jshintrc
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"node": true,
|
||||
"laxcomma": true,
|
||||
"indent": 2,
|
||||
"globalstrict": true,
|
||||
"maxparams": 6,
|
||||
"maxdepth": 3,
|
||||
"maxstatements": 20,
|
||||
"maxcomplexity": 10,
|
||||
"maxlen": 100,
|
||||
"globals": {
|
||||
"describe": true,
|
||||
"it": true,
|
||||
"before": true,
|
||||
"after": true
|
||||
}
|
||||
}
|
15
node_modules/streamroller/.npmignore
generated
vendored
Normal file
15
node_modules/streamroller/.npmignore
generated
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
lib-cov
|
||||
*.seed
|
||||
*.log
|
||||
*.csv
|
||||
*.dat
|
||||
*.out
|
||||
*.pid
|
||||
*.gz
|
||||
|
||||
pids
|
||||
logs
|
||||
results
|
||||
|
||||
npm-debug.log
|
||||
node_modules
|
7
node_modules/streamroller/.travis.yml
generated
vendored
Normal file
7
node_modules/streamroller/.travis.yml
generated
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
language: node_js
|
||||
sudo: false
|
||||
node_js:
|
||||
- "6"
|
||||
- "5"
|
||||
- "4"
|
||||
- "0.12"
|
20
node_modules/streamroller/LICENSE
generated
vendored
Normal file
20
node_modules/streamroller/LICENSE
generated
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013 Gareth Jones
|
||||
|
||||
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.
|
54
node_modules/streamroller/README.md
generated
vendored
Normal file
54
node_modules/streamroller/README.md
generated
vendored
Normal file
@ -0,0 +1,54 @@
|
||||
streamroller
|
||||
============
|
||||
|
||||
node.js file streams that roll over when they reach a maximum size, or a date/time.
|
||||
|
||||
npm install streamroller
|
||||
|
||||
## usage
|
||||
|
||||
var rollers = require('streamroller');
|
||||
var stream = new rollers.RollingFileStream('myfile', 1024, 3);
|
||||
stream.write("stuff");
|
||||
stream.end();
|
||||
|
||||
The streams behave the same as standard node.js streams, except that when certain conditions are met they will rename the current file to a backup and start writing to a new file.
|
||||
|
||||
### new RollingFileStream(filename [, maxSize, numBackups, options])
|
||||
* `filename` (String)
|
||||
* `maxSize` - the size in bytes to trigger a rollover, if not provided this defaults to MAX_SAFE_INTEGER and the stream will not roll.
|
||||
* `numBackups` - the number of old files to keep
|
||||
* `options` - Object
|
||||
* `encoding` - defaults to 'utf8'
|
||||
* `mode` - defaults to 0644
|
||||
* `flags` - defaults to 'a'
|
||||
* `compress` - (boolean) defaults to `false` - compress the backup files using gzip (files will have `.gz` extension).
|
||||
|
||||
This returns a `WritableStream`. When the current file being written to (given by `filename`) gets up to or larger than `maxSize`, then the current file will be renamed to `filename.1` and a new file will start being written to. Up to `numBackups` of old files are maintained, so if `numBackups` is 3 then there will be 4 files:
|
||||
<pre>
|
||||
filename
|
||||
filename.1
|
||||
filename.2
|
||||
filename.3
|
||||
</pre>
|
||||
When filename size >= maxSize then:
|
||||
<pre>
|
||||
filename -> filename.1
|
||||
filename.1 -> filename.2
|
||||
filename.2 -> filename.3
|
||||
filename.3 gets overwritten
|
||||
filename is a new file
|
||||
</pre>
|
||||
|
||||
### new DateRollingFileStream(filename, pattern, options)
|
||||
* `filename` (String)
|
||||
* `pattern` (String) - the date pattern to trigger rolling (see below)
|
||||
* `options` - Object
|
||||
* `encoding` - defaults to 'utf8'
|
||||
* `mode` defaults to 0644
|
||||
* `flags` defaults to 'a'
|
||||
* `compress` - (boolean) compress the backup files, defaults to false
|
||||
* `alwaysIncludePattern` - (boolean) extend the initial file with the pattern, defaults to false
|
||||
|
||||
|
||||
This returns a `WritableStream`. When the current time, formatted as `pattern`, changes then the current file will be renamed to `filename.formattedDate` where `formattedDate` is the result of processing the date through the pattern, and a new file will begin to be written. Streamroller uses [date-format](http://github.com/nomiddlename/date-format) to format dates, and the `pattern` should use the date-format format. e.g. with a `pattern` of `"yyyy-MM-dd"`, and assuming today is August 29, 2013 then writing to the stream today will just write to `filename`. At midnight, `filename` will be renamed to `filename.2013-08-29` and a new `filename` will be created. If `options.alwaysIncludePattern` is true, then the initial file will be `filename.2013-08-29` and no renaming will occur at midnight, but a new file will be written to with the name `filename.2013-08-30`.
|
118
node_modules/streamroller/lib/BaseRollingFileStream.js
generated
vendored
Normal file
118
node_modules/streamroller/lib/BaseRollingFileStream.js
generated
vendored
Normal file
@ -0,0 +1,118 @@
|
||||
"use strict";
|
||||
var fs = require('fs')
|
||||
, zlib = require('zlib')
|
||||
, debug = require('debug')('streamroller:BaseRollingFileStream')
|
||||
, mkdirp = require('mkdirp')
|
||||
, path = require('path')
|
||||
, util = require('util')
|
||||
, stream = require('readable-stream');
|
||||
|
||||
module.exports = BaseRollingFileStream;
|
||||
|
||||
function BaseRollingFileStream(filename, options) {
|
||||
debug("In BaseRollingFileStream");
|
||||
this.filename = filename;
|
||||
this.options = options || {};
|
||||
this.options.encoding = this.options.encoding || 'utf8';
|
||||
this.options.mode = this.options.mode || parseInt('0644', 8);
|
||||
this.options.flags = this.options.flags || 'a';
|
||||
|
||||
this.currentSize = 0;
|
||||
|
||||
function currentFileSize(file) {
|
||||
var fileSize = 0;
|
||||
try {
|
||||
fileSize = fs.statSync(file).size;
|
||||
} catch (e) {
|
||||
// file does not exist
|
||||
}
|
||||
return fileSize;
|
||||
}
|
||||
|
||||
function throwErrorIfArgumentsAreNotValid() {
|
||||
if (!filename) {
|
||||
throw new Error("You must specify a filename");
|
||||
}
|
||||
}
|
||||
|
||||
throwErrorIfArgumentsAreNotValid();
|
||||
debug("Calling BaseRollingFileStream.super");
|
||||
BaseRollingFileStream.super_.call(this);
|
||||
this.openTheStream();
|
||||
this.currentSize = currentFileSize(this.filename);
|
||||
}
|
||||
util.inherits(BaseRollingFileStream, stream.Writable);
|
||||
|
||||
BaseRollingFileStream.prototype._write = function(chunk, encoding, callback) {
|
||||
var that = this;
|
||||
function writeTheChunk() {
|
||||
debug("writing the chunk to the underlying stream");
|
||||
that.currentSize += chunk.length;
|
||||
try {
|
||||
that.theStream.write(chunk, encoding, callback);
|
||||
}
|
||||
catch (err){
|
||||
debug(err);
|
||||
callback();
|
||||
}
|
||||
}
|
||||
|
||||
debug("in _write");
|
||||
|
||||
if (this.shouldRoll()) {
|
||||
this.currentSize = 0;
|
||||
this.roll(this.filename, writeTheChunk);
|
||||
} else {
|
||||
writeTheChunk();
|
||||
}
|
||||
};
|
||||
|
||||
BaseRollingFileStream.prototype.openTheStream = function(cb) {
|
||||
debug("opening the underlying stream");
|
||||
var that = this;
|
||||
mkdirp.sync(path.dirname(this.filename));
|
||||
this.theStream = fs.createWriteStream(this.filename, this.options);
|
||||
this.theStream.on('error', function(err) {
|
||||
that.emit('error', err);
|
||||
});
|
||||
if (cb) {
|
||||
this.theStream.on("open", cb);
|
||||
}
|
||||
};
|
||||
|
||||
BaseRollingFileStream.prototype.closeTheStream = function(cb) {
|
||||
debug("closing the underlying stream");
|
||||
this.theStream.end(cb);
|
||||
};
|
||||
|
||||
BaseRollingFileStream.prototype.compress = function(filename, cb) {
|
||||
debug('Compressing ', filename, ' -> ', filename, '.gz');
|
||||
var gzip = zlib.createGzip();
|
||||
var inp = fs.createReadStream(filename);
|
||||
var out = fs.createWriteStream(filename+".gz");
|
||||
inp.pipe(gzip).pipe(out);
|
||||
|
||||
out.on('finish', function(err) {
|
||||
debug('Removing original ', filename);
|
||||
fs.unlink(filename, cb);
|
||||
});
|
||||
};
|
||||
|
||||
BaseRollingFileStream.prototype.shouldRoll = function() {
|
||||
return false; // default behaviour is never to roll
|
||||
};
|
||||
|
||||
BaseRollingFileStream.prototype.roll = function(filename, callback) {
|
||||
callback(); // default behaviour is not to do anything
|
||||
};
|
||||
|
||||
BaseRollingFileStream.prototype.end = function(chunk, encoding, callback) {
|
||||
var self = this;
|
||||
this.theStream.end(chunk, encoding, function(err) {
|
||||
stream.Writable.prototype.end.call(self, function() {
|
||||
if (callback) {
|
||||
callback(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
136
node_modules/streamroller/lib/DateRollingFileStream.js
generated
vendored
Normal file
136
node_modules/streamroller/lib/DateRollingFileStream.js
generated
vendored
Normal file
@ -0,0 +1,136 @@
|
||||
"use strict";
|
||||
var BaseRollingFileStream = require('./BaseRollingFileStream')
|
||||
, debug = require('debug')('streamroller:DateRollingFileStream')
|
||||
, format = require('date-format')
|
||||
, fs = require('fs')
|
||||
, path = require('path')
|
||||
, util = require('util');
|
||||
|
||||
module.exports = DateRollingFileStream;
|
||||
|
||||
function findTimestampFromFileIfExists(filename, now) {
|
||||
return fs.existsSync(filename) ? fs.statSync(filename).mtime : new Date(now());
|
||||
}
|
||||
|
||||
function DateRollingFileStream(filename, pattern, options, now) {
|
||||
debug("Now is ", now);
|
||||
if (pattern && typeof(pattern) === 'object') {
|
||||
now = options;
|
||||
options = pattern;
|
||||
pattern = null;
|
||||
}
|
||||
this.pattern = pattern || '.yyyy-MM-dd';
|
||||
this.now = now || Date.now;
|
||||
this.lastTimeWeWroteSomething = format.asString(
|
||||
this.pattern,
|
||||
findTimestampFromFileIfExists(filename, this.now)
|
||||
);
|
||||
|
||||
this.baseFilename = filename;
|
||||
this.alwaysIncludePattern = false;
|
||||
|
||||
if (options) {
|
||||
if (options.alwaysIncludePattern) {
|
||||
this.alwaysIncludePattern = true;
|
||||
filename = this.baseFilename + this.lastTimeWeWroteSomething;
|
||||
}
|
||||
delete options.alwaysIncludePattern;
|
||||
if (Object.keys(options).length === 0) {
|
||||
options = null;
|
||||
}
|
||||
}
|
||||
debug("this.now is ", this.now, ", now is ", now);
|
||||
|
||||
DateRollingFileStream.super_.call(this, filename, options);
|
||||
}
|
||||
util.inherits(DateRollingFileStream, BaseRollingFileStream);
|
||||
|
||||
DateRollingFileStream.prototype.shouldRoll = function () {
|
||||
var lastTime = this.lastTimeWeWroteSomething,
|
||||
thisTime = format.asString(this.pattern, new Date(this.now()));
|
||||
|
||||
debug("DateRollingFileStream.shouldRoll with now = ",
|
||||
this.now(), ", thisTime = ", thisTime, ", lastTime = ", lastTime);
|
||||
|
||||
this.lastTimeWeWroteSomething = thisTime;
|
||||
this.previousTime = lastTime;
|
||||
|
||||
return thisTime !== lastTime;
|
||||
};
|
||||
|
||||
DateRollingFileStream.prototype.roll = function (filename, callback) {
|
||||
var that = this;
|
||||
|
||||
debug("Starting roll");
|
||||
|
||||
if (this.alwaysIncludePattern) {
|
||||
this.filename = this.baseFilename + this.lastTimeWeWroteSomething;
|
||||
this.closeTheStream(
|
||||
this.compressIfNeeded.bind(this, filename,
|
||||
this.removeOldFilesIfNeeded.bind(this,
|
||||
this.openTheStream.bind(this, callback))));
|
||||
} else {
|
||||
var newFilename = this.baseFilename + this.previousTime;
|
||||
this.closeTheStream(
|
||||
deleteAnyExistingFile.bind(null,
|
||||
renameTheCurrentFile.bind(null,
|
||||
this.compressIfNeeded.bind(this, newFilename,
|
||||
this.removeOldFilesIfNeeded.bind(this,
|
||||
this.openTheStream.bind(this, callback))))));
|
||||
}
|
||||
|
||||
function deleteAnyExistingFile(cb) {
|
||||
//on windows, you can get a EEXIST error if you rename a file to an existing file
|
||||
//so, we'll try to delete the file we're renaming to first
|
||||
fs.unlink(newFilename, function (err) {
|
||||
|
||||
//ignore err: if we could not delete, it's most likely that it doesn't exist
|
||||
cb();
|
||||
});
|
||||
}
|
||||
|
||||
function renameTheCurrentFile(cb) {
|
||||
debug("Renaming the ", filename, " -> ", newFilename);
|
||||
fs.rename(filename, newFilename, cb);
|
||||
}
|
||||
};
|
||||
|
||||
DateRollingFileStream.prototype.compressIfNeeded = function (filename, cb) {
|
||||
debug("Checking if we need to compress the old file");
|
||||
if (this.options.compress) {
|
||||
this.compress(filename, cb);
|
||||
} else {
|
||||
cb();
|
||||
}
|
||||
};
|
||||
|
||||
DateRollingFileStream.prototype.removeOldFilesIfNeeded = function (cb) {
|
||||
debug("Checking if we need to delete old files");
|
||||
if (this.options.daysToKeep && this.options.daysToKeep > 0) {
|
||||
var oldestDate = new Date(this.now() - (this.options.daysToKeep * (24 * 60 * 60 * 1000)));
|
||||
debug("Will delete any log files modified before ", oldestDate.toString());
|
||||
|
||||
this.removeFilesOlderThan(oldestDate);
|
||||
}
|
||||
cb();
|
||||
};
|
||||
|
||||
DateRollingFileStream.prototype.removeFilesOlderThan = function (oldestDate) {
|
||||
|
||||
// Loop through any log files and delete any whose mtime is earlier than oldestDate
|
||||
var dirToScan = path.dirname(this.baseFilename);
|
||||
var fileToMatch = path.basename(this.baseFilename);
|
||||
var filesToCheck = fs.readdirSync(dirToScan).filter(function (file) {
|
||||
return file.indexOf(fileToMatch) > -1;
|
||||
});
|
||||
for (var i = 0; i < filesToCheck.length; i++) {
|
||||
var fileToCheck = path.join(dirToScan, filesToCheck[i]);
|
||||
var fileStats = fs.statSync(fileToCheck);
|
||||
if (fileStats.mtime < oldestDate) {
|
||||
debug("Deleting old log ", filesToCheck);
|
||||
fs.unlinkSync(fileToCheck);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
110
node_modules/streamroller/lib/RollingFileStream.js
generated
vendored
Normal file
110
node_modules/streamroller/lib/RollingFileStream.js
generated
vendored
Normal file
@ -0,0 +1,110 @@
|
||||
"use strict";
|
||||
var BaseRollingFileStream = require('./BaseRollingFileStream')
|
||||
, debug = require('debug')('streamroller:RollingFileStream')
|
||||
, util = require('util')
|
||||
, path = require('path')
|
||||
, child_process = require('child_process')
|
||||
, fs = require('fs');
|
||||
|
||||
module.exports = RollingFileStream;
|
||||
|
||||
function RollingFileStream (filename, size, backups, options) {
|
||||
//if you don't specify a size, this will behave like a normal file stream
|
||||
this.size = size || Number.MAX_SAFE_INTEGER;
|
||||
this.backups = backups || 1;
|
||||
|
||||
function throwErrorIfArgumentsAreNotValid() {
|
||||
if (!filename || size <= 0) {
|
||||
throw new Error("You must specify a filename and file size");
|
||||
}
|
||||
}
|
||||
|
||||
throwErrorIfArgumentsAreNotValid();
|
||||
|
||||
RollingFileStream.super_.call(this, filename, options);
|
||||
}
|
||||
util.inherits(RollingFileStream, BaseRollingFileStream);
|
||||
|
||||
RollingFileStream.prototype.shouldRoll = function() {
|
||||
debug("should roll with current size " + this.currentSize + " and max size " + this.size);
|
||||
return this.currentSize >= this.size;
|
||||
};
|
||||
|
||||
RollingFileStream.prototype.roll = function(filename, callback) {
|
||||
var that = this,
|
||||
nameMatcher = new RegExp('^' + path.basename(filename));
|
||||
|
||||
function justTheseFiles (item) {
|
||||
return nameMatcher.test(item);
|
||||
}
|
||||
|
||||
function index(filename_) {
|
||||
debug('Calculating index of '+filename_);
|
||||
return parseInt(filename_.substring((path.basename(filename) + '.').length), 10) || 0;
|
||||
}
|
||||
|
||||
function byIndex(a, b) {
|
||||
if (index(a) > index(b)) {
|
||||
return 1;
|
||||
} else if (index(a) < index(b) ) {
|
||||
return -1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
function increaseFileIndex (fileToRename, cb) {
|
||||
var idx = index(fileToRename);
|
||||
debug('Index of ' + fileToRename + ' is ' + idx);
|
||||
if (idx < that.backups) {
|
||||
|
||||
var ext = path.extname(fileToRename);
|
||||
var destination = filename + '.' + (idx+1);
|
||||
if (that.options.compress && /^gz$/.test(ext.substring(1))) {
|
||||
destination+=ext;
|
||||
}
|
||||
//on windows, you can get a EEXIST error if you rename a file to an existing file
|
||||
//so, we'll try to delete the file we're renaming to first
|
||||
fs.unlink(destination, function (err) {
|
||||
//ignore err: if we could not delete, it's most likely that it doesn't exist
|
||||
debug('Renaming ' + fileToRename + ' -> ' + destination);
|
||||
fs.rename(path.join(path.dirname(filename), fileToRename), destination, function(err) {
|
||||
if (err) {
|
||||
cb(err);
|
||||
} else {
|
||||
if (that.options.compress && ext!=".gz") {
|
||||
that.compress(destination, cb);
|
||||
} else {
|
||||
cb();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
cb();
|
||||
}
|
||||
}
|
||||
|
||||
function renameTheFiles(cb) {
|
||||
//roll the backups (rename file.n to file.n+1, where n <= numBackups)
|
||||
debug("Renaming the old files");
|
||||
fs.readdir(path.dirname(filename), function (err, files) {
|
||||
if (err) {
|
||||
return cb(err);
|
||||
}
|
||||
var filesToProcess = files.filter(justTheseFiles).sort(byIndex);
|
||||
(function processOne(err) {
|
||||
var file = filesToProcess.pop();
|
||||
if (!file || err) { return cb(err); }
|
||||
increaseFileIndex(file, processOne);
|
||||
})();
|
||||
});
|
||||
}
|
||||
|
||||
debug("Rolling, rolling, rolling");
|
||||
this.closeTheStream(
|
||||
renameTheFiles.bind(null,
|
||||
this.openTheStream.bind(this,
|
||||
callback)));
|
||||
|
||||
};
|
3
node_modules/streamroller/lib/index.js
generated
vendored
Normal file
3
node_modules/streamroller/lib/index.js
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
exports.RollingFileStream = require('./RollingFileStream');
|
||||
exports.DateRollingFileStream = require('./DateRollingFileStream');
|
5
node_modules/streamroller/node_modules/readable-stream/.npmignore
generated
vendored
Normal file
5
node_modules/streamroller/node_modules/readable-stream/.npmignore
generated
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
build/
|
||||
test/
|
||||
examples/
|
||||
fs.js
|
||||
zlib.js
|
18
node_modules/streamroller/node_modules/readable-stream/LICENSE
generated
vendored
Normal file
18
node_modules/streamroller/node_modules/readable-stream/LICENSE
generated
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
Copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
||||
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.
|
15
node_modules/streamroller/node_modules/readable-stream/README.md
generated
vendored
Normal file
15
node_modules/streamroller/node_modules/readable-stream/README.md
generated
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
# readable-stream
|
||||
|
||||
***Node-core streams for userland***
|
||||
|
||||
[](https://nodei.co/npm/readable-stream/)
|
||||
[](https://nodei.co/npm/readable-stream/)
|
||||
|
||||
This package is a mirror of the Streams2 and Streams3 implementations in Node-core.
|
||||
|
||||
If you want to guarantee a stable streams base, regardless of what version of Node you, or the users of your libraries are using, use **readable-stream** *only* and avoid the *"stream"* module in Node-core.
|
||||
|
||||
**readable-stream** comes in two major versions, v1.0.x and v1.1.x. The former tracks the Streams2 implementation in Node 0.10, including bug-fixes and minor improvements as they are added. The latter tracks Streams3 as it develops in Node 0.11; we will likely see a v1.2.x branch for Node 0.12.
|
||||
|
||||
**readable-stream** uses proper patch-level versioning so if you pin to `"~1.0.0"` you’ll get the latest Node 0.10 Streams2 implementation, including any fixes and minor non-breaking improvements. The patch-level versions of 1.0.x and 1.1.x should mirror the patch-level versions of Node-core releases. You should prefer the **1.0.x** releases for now and when you’re ready to start using Streams3, pin to `"~1.1.0"`
|
||||
|
1
node_modules/streamroller/node_modules/readable-stream/duplex.js
generated
vendored
Normal file
1
node_modules/streamroller/node_modules/readable-stream/duplex.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
module.exports = require("./lib/_stream_duplex.js")
|
923
node_modules/streamroller/node_modules/readable-stream/float.patch
generated
vendored
Normal file
923
node_modules/streamroller/node_modules/readable-stream/float.patch
generated
vendored
Normal file
@ -0,0 +1,923 @@
|
||||
diff --git a/lib/_stream_duplex.js b/lib/_stream_duplex.js
|
||||
index c5a741c..a2e0d8e 100644
|
||||
--- a/lib/_stream_duplex.js
|
||||
+++ b/lib/_stream_duplex.js
|
||||
@@ -26,8 +26,8 @@
|
||||
|
||||
module.exports = Duplex;
|
||||
var util = require('util');
|
||||
-var Readable = require('_stream_readable');
|
||||
-var Writable = require('_stream_writable');
|
||||
+var Readable = require('./_stream_readable');
|
||||
+var Writable = require('./_stream_writable');
|
||||
|
||||
util.inherits(Duplex, Readable);
|
||||
|
||||
diff --git a/lib/_stream_passthrough.js b/lib/_stream_passthrough.js
|
||||
index a5e9864..330c247 100644
|
||||
--- a/lib/_stream_passthrough.js
|
||||
+++ b/lib/_stream_passthrough.js
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
module.exports = PassThrough;
|
||||
|
||||
-var Transform = require('_stream_transform');
|
||||
+var Transform = require('./_stream_transform');
|
||||
var util = require('util');
|
||||
util.inherits(PassThrough, Transform);
|
||||
|
||||
diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js
|
||||
index 0c3fe3e..90a8298 100644
|
||||
--- a/lib/_stream_readable.js
|
||||
+++ b/lib/_stream_readable.js
|
||||
@@ -23,10 +23,34 @@ module.exports = Readable;
|
||||
Readable.ReadableState = ReadableState;
|
||||
|
||||
var EE = require('events').EventEmitter;
|
||||
+if (!EE.listenerCount) EE.listenerCount = function(emitter, type) {
|
||||
+ return emitter.listeners(type).length;
|
||||
+};
|
||||
+
|
||||
+if (!global.setImmediate) global.setImmediate = function setImmediate(fn) {
|
||||
+ return setTimeout(fn, 0);
|
||||
+};
|
||||
+if (!global.clearImmediate) global.clearImmediate = function clearImmediate(i) {
|
||||
+ return clearTimeout(i);
|
||||
+};
|
||||
+
|
||||
var Stream = require('stream');
|
||||
var util = require('util');
|
||||
+if (!util.isUndefined) {
|
||||
+ var utilIs = require('core-util-is');
|
||||
+ for (var f in utilIs) {
|
||||
+ util[f] = utilIs[f];
|
||||
+ }
|
||||
+}
|
||||
var StringDecoder;
|
||||
-var debug = util.debuglog('stream');
|
||||
+var debug;
|
||||
+if (util.debuglog)
|
||||
+ debug = util.debuglog('stream');
|
||||
+else try {
|
||||
+ debug = require('debuglog')('stream');
|
||||
+} catch (er) {
|
||||
+ debug = function() {};
|
||||
+}
|
||||
|
||||
util.inherits(Readable, Stream);
|
||||
|
||||
@@ -380,7 +404,7 @@ function chunkInvalid(state, chunk) {
|
||||
|
||||
|
||||
function onEofChunk(stream, state) {
|
||||
- if (state.decoder && !state.ended) {
|
||||
+ if (state.decoder && !state.ended && state.decoder.end) {
|
||||
var chunk = state.decoder.end();
|
||||
if (chunk && chunk.length) {
|
||||
state.buffer.push(chunk);
|
||||
diff --git a/lib/_stream_transform.js b/lib/_stream_transform.js
|
||||
index b1f9fcc..b0caf57 100644
|
||||
--- a/lib/_stream_transform.js
|
||||
+++ b/lib/_stream_transform.js
|
||||
@@ -64,8 +64,14 @@
|
||||
|
||||
module.exports = Transform;
|
||||
|
||||
-var Duplex = require('_stream_duplex');
|
||||
+var Duplex = require('./_stream_duplex');
|
||||
var util = require('util');
|
||||
+if (!util.isUndefined) {
|
||||
+ var utilIs = require('core-util-is');
|
||||
+ for (var f in utilIs) {
|
||||
+ util[f] = utilIs[f];
|
||||
+ }
|
||||
+}
|
||||
util.inherits(Transform, Duplex);
|
||||
|
||||
|
||||
diff --git a/lib/_stream_writable.js b/lib/_stream_writable.js
|
||||
index ba2e920..f49288b 100644
|
||||
--- a/lib/_stream_writable.js
|
||||
+++ b/lib/_stream_writable.js
|
||||
@@ -27,6 +27,12 @@ module.exports = Writable;
|
||||
Writable.WritableState = WritableState;
|
||||
|
||||
var util = require('util');
|
||||
+if (!util.isUndefined) {
|
||||
+ var utilIs = require('core-util-is');
|
||||
+ for (var f in utilIs) {
|
||||
+ util[f] = utilIs[f];
|
||||
+ }
|
||||
+}
|
||||
var Stream = require('stream');
|
||||
|
||||
util.inherits(Writable, Stream);
|
||||
@@ -119,7 +125,7 @@ function WritableState(options, stream) {
|
||||
function Writable(options) {
|
||||
// Writable ctor is applied to Duplexes, though they're not
|
||||
// instanceof Writable, they're instanceof Readable.
|
||||
- if (!(this instanceof Writable) && !(this instanceof Stream.Duplex))
|
||||
+ if (!(this instanceof Writable) && !(this instanceof require('./_stream_duplex')))
|
||||
return new Writable(options);
|
||||
|
||||
this._writableState = new WritableState(options, this);
|
||||
diff --git a/test/simple/test-stream-big-push.js b/test/simple/test-stream-big-push.js
|
||||
index e3787e4..8cd2127 100644
|
||||
--- a/test/simple/test-stream-big-push.js
|
||||
+++ b/test/simple/test-stream-big-push.js
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
var common = require('../common');
|
||||
var assert = require('assert');
|
||||
-var stream = require('stream');
|
||||
+var stream = require('../../');
|
||||
var str = 'asdfasdfasdfasdfasdf';
|
||||
|
||||
var r = new stream.Readable({
|
||||
diff --git a/test/simple/test-stream-end-paused.js b/test/simple/test-stream-end-paused.js
|
||||
index bb73777..d40efc7 100644
|
||||
--- a/test/simple/test-stream-end-paused.js
|
||||
+++ b/test/simple/test-stream-end-paused.js
|
||||
@@ -25,7 +25,7 @@ var gotEnd = false;
|
||||
|
||||
// Make sure we don't miss the end event for paused 0-length streams
|
||||
|
||||
-var Readable = require('stream').Readable;
|
||||
+var Readable = require('../../').Readable;
|
||||
var stream = new Readable();
|
||||
var calledRead = false;
|
||||
stream._read = function() {
|
||||
diff --git a/test/simple/test-stream-pipe-after-end.js b/test/simple/test-stream-pipe-after-end.js
|
||||
index b46ee90..0be8366 100644
|
||||
--- a/test/simple/test-stream-pipe-after-end.js
|
||||
+++ b/test/simple/test-stream-pipe-after-end.js
|
||||
@@ -22,8 +22,8 @@
|
||||
var common = require('../common');
|
||||
var assert = require('assert');
|
||||
|
||||
-var Readable = require('_stream_readable');
|
||||
-var Writable = require('_stream_writable');
|
||||
+var Readable = require('../../lib/_stream_readable');
|
||||
+var Writable = require('../../lib/_stream_writable');
|
||||
var util = require('util');
|
||||
|
||||
util.inherits(TestReadable, Readable);
|
||||
diff --git a/test/simple/test-stream-pipe-cleanup.js b/test/simple/test-stream-pipe-cleanup.js
|
||||
deleted file mode 100644
|
||||
index f689358..0000000
|
||||
--- a/test/simple/test-stream-pipe-cleanup.js
|
||||
+++ /dev/null
|
||||
@@ -1,122 +0,0 @@
|
||||
-// Copyright Joyent, Inc. and other Node contributors.
|
||||
-//
|
||||
-// 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.
|
||||
-
|
||||
-// This test asserts that Stream.prototype.pipe does not leave listeners
|
||||
-// hanging on the source or dest.
|
||||
-
|
||||
-var common = require('../common');
|
||||
-var stream = require('stream');
|
||||
-var assert = require('assert');
|
||||
-var util = require('util');
|
||||
-
|
||||
-function Writable() {
|
||||
- this.writable = true;
|
||||
- this.endCalls = 0;
|
||||
- stream.Stream.call(this);
|
||||
-}
|
||||
-util.inherits(Writable, stream.Stream);
|
||||
-Writable.prototype.end = function() {
|
||||
- this.endCalls++;
|
||||
-};
|
||||
-
|
||||
-Writable.prototype.destroy = function() {
|
||||
- this.endCalls++;
|
||||
-};
|
||||
-
|
||||
-function Readable() {
|
||||
- this.readable = true;
|
||||
- stream.Stream.call(this);
|
||||
-}
|
||||
-util.inherits(Readable, stream.Stream);
|
||||
-
|
||||
-function Duplex() {
|
||||
- this.readable = true;
|
||||
- Writable.call(this);
|
||||
-}
|
||||
-util.inherits(Duplex, Writable);
|
||||
-
|
||||
-var i = 0;
|
||||
-var limit = 100;
|
||||
-
|
||||
-var w = new Writable();
|
||||
-
|
||||
-var r;
|
||||
-
|
||||
-for (i = 0; i < limit; i++) {
|
||||
- r = new Readable();
|
||||
- r.pipe(w);
|
||||
- r.emit('end');
|
||||
-}
|
||||
-assert.equal(0, r.listeners('end').length);
|
||||
-assert.equal(limit, w.endCalls);
|
||||
-
|
||||
-w.endCalls = 0;
|
||||
-
|
||||
-for (i = 0; i < limit; i++) {
|
||||
- r = new Readable();
|
||||
- r.pipe(w);
|
||||
- r.emit('close');
|
||||
-}
|
||||
-assert.equal(0, r.listeners('close').length);
|
||||
-assert.equal(limit, w.endCalls);
|
||||
-
|
||||
-w.endCalls = 0;
|
||||
-
|
||||
-r = new Readable();
|
||||
-
|
||||
-for (i = 0; i < limit; i++) {
|
||||
- w = new Writable();
|
||||
- r.pipe(w);
|
||||
- w.emit('close');
|
||||
-}
|
||||
-assert.equal(0, w.listeners('close').length);
|
||||
-
|
||||
-r = new Readable();
|
||||
-w = new Writable();
|
||||
-var d = new Duplex();
|
||||
-r.pipe(d); // pipeline A
|
||||
-d.pipe(w); // pipeline B
|
||||
-assert.equal(r.listeners('end').length, 2); // A.onend, A.cleanup
|
||||
-assert.equal(r.listeners('close').length, 2); // A.onclose, A.cleanup
|
||||
-assert.equal(d.listeners('end').length, 2); // B.onend, B.cleanup
|
||||
-assert.equal(d.listeners('close').length, 3); // A.cleanup, B.onclose, B.cleanup
|
||||
-assert.equal(w.listeners('end').length, 0);
|
||||
-assert.equal(w.listeners('close').length, 1); // B.cleanup
|
||||
-
|
||||
-r.emit('end');
|
||||
-assert.equal(d.endCalls, 1);
|
||||
-assert.equal(w.endCalls, 0);
|
||||
-assert.equal(r.listeners('end').length, 0);
|
||||
-assert.equal(r.listeners('close').length, 0);
|
||||
-assert.equal(d.listeners('end').length, 2); // B.onend, B.cleanup
|
||||
-assert.equal(d.listeners('close').length, 2); // B.onclose, B.cleanup
|
||||
-assert.equal(w.listeners('end').length, 0);
|
||||
-assert.equal(w.listeners('close').length, 1); // B.cleanup
|
||||
-
|
||||
-d.emit('end');
|
||||
-assert.equal(d.endCalls, 1);
|
||||
-assert.equal(w.endCalls, 1);
|
||||
-assert.equal(r.listeners('end').length, 0);
|
||||
-assert.equal(r.listeners('close').length, 0);
|
||||
-assert.equal(d.listeners('end').length, 0);
|
||||
-assert.equal(d.listeners('close').length, 0);
|
||||
-assert.equal(w.listeners('end').length, 0);
|
||||
-assert.equal(w.listeners('close').length, 0);
|
||||
diff --git a/test/simple/test-stream-pipe-error-handling.js b/test/simple/test-stream-pipe-error-handling.js
|
||||
index c5d724b..c7d6b7d 100644
|
||||
--- a/test/simple/test-stream-pipe-error-handling.js
|
||||
+++ b/test/simple/test-stream-pipe-error-handling.js
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
var common = require('../common');
|
||||
var assert = require('assert');
|
||||
-var Stream = require('stream').Stream;
|
||||
+var Stream = require('../../').Stream;
|
||||
|
||||
(function testErrorListenerCatches() {
|
||||
var source = new Stream();
|
||||
diff --git a/test/simple/test-stream-pipe-event.js b/test/simple/test-stream-pipe-event.js
|
||||
index cb9d5fe..56f8d61 100644
|
||||
--- a/test/simple/test-stream-pipe-event.js
|
||||
+++ b/test/simple/test-stream-pipe-event.js
|
||||
@@ -20,7 +20,7 @@
|
||||
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
var common = require('../common');
|
||||
-var stream = require('stream');
|
||||
+var stream = require('../../');
|
||||
var assert = require('assert');
|
||||
var util = require('util');
|
||||
|
||||
diff --git a/test/simple/test-stream-push-order.js b/test/simple/test-stream-push-order.js
|
||||
index f2e6ec2..a5c9bf9 100644
|
||||
--- a/test/simple/test-stream-push-order.js
|
||||
+++ b/test/simple/test-stream-push-order.js
|
||||
@@ -20,7 +20,7 @@
|
||||
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
var common = require('../common.js');
|
||||
-var Readable = require('stream').Readable;
|
||||
+var Readable = require('../../').Readable;
|
||||
var assert = require('assert');
|
||||
|
||||
var s = new Readable({
|
||||
diff --git a/test/simple/test-stream-push-strings.js b/test/simple/test-stream-push-strings.js
|
||||
index 06f43dc..1701a9a 100644
|
||||
--- a/test/simple/test-stream-push-strings.js
|
||||
+++ b/test/simple/test-stream-push-strings.js
|
||||
@@ -22,7 +22,7 @@
|
||||
var common = require('../common');
|
||||
var assert = require('assert');
|
||||
|
||||
-var Readable = require('stream').Readable;
|
||||
+var Readable = require('../../').Readable;
|
||||
var util = require('util');
|
||||
|
||||
util.inherits(MyStream, Readable);
|
||||
diff --git a/test/simple/test-stream-readable-event.js b/test/simple/test-stream-readable-event.js
|
||||
index ba6a577..a8e6f7b 100644
|
||||
--- a/test/simple/test-stream-readable-event.js
|
||||
+++ b/test/simple/test-stream-readable-event.js
|
||||
@@ -22,7 +22,7 @@
|
||||
var common = require('../common');
|
||||
var assert = require('assert');
|
||||
|
||||
-var Readable = require('stream').Readable;
|
||||
+var Readable = require('../../').Readable;
|
||||
|
||||
(function first() {
|
||||
// First test, not reading when the readable is added.
|
||||
diff --git a/test/simple/test-stream-readable-flow-recursion.js b/test/simple/test-stream-readable-flow-recursion.js
|
||||
index 2891ad6..11689ba 100644
|
||||
--- a/test/simple/test-stream-readable-flow-recursion.js
|
||||
+++ b/test/simple/test-stream-readable-flow-recursion.js
|
||||
@@ -27,7 +27,7 @@ var assert = require('assert');
|
||||
// more data continuously, but without triggering a nextTick
|
||||
// warning or RangeError.
|
||||
|
||||
-var Readable = require('stream').Readable;
|
||||
+var Readable = require('../../').Readable;
|
||||
|
||||
// throw an error if we trigger a nextTick warning.
|
||||
process.throwDeprecation = true;
|
||||
diff --git a/test/simple/test-stream-unshift-empty-chunk.js b/test/simple/test-stream-unshift-empty-chunk.js
|
||||
index 0c96476..7827538 100644
|
||||
--- a/test/simple/test-stream-unshift-empty-chunk.js
|
||||
+++ b/test/simple/test-stream-unshift-empty-chunk.js
|
||||
@@ -24,7 +24,7 @@ var assert = require('assert');
|
||||
|
||||
// This test verifies that stream.unshift(Buffer(0)) or
|
||||
// stream.unshift('') does not set state.reading=false.
|
||||
-var Readable = require('stream').Readable;
|
||||
+var Readable = require('../../').Readable;
|
||||
|
||||
var r = new Readable();
|
||||
var nChunks = 10;
|
||||
diff --git a/test/simple/test-stream-unshift-read-race.js b/test/simple/test-stream-unshift-read-race.js
|
||||
index 83fd9fa..17c18aa 100644
|
||||
--- a/test/simple/test-stream-unshift-read-race.js
|
||||
+++ b/test/simple/test-stream-unshift-read-race.js
|
||||
@@ -29,7 +29,7 @@ var assert = require('assert');
|
||||
// 3. push() after the EOF signaling null is an error.
|
||||
// 4. _read() is not called after pushing the EOF null chunk.
|
||||
|
||||
-var stream = require('stream');
|
||||
+var stream = require('../../');
|
||||
var hwm = 10;
|
||||
var r = stream.Readable({ highWaterMark: hwm });
|
||||
var chunks = 10;
|
||||
@@ -51,7 +51,14 @@ r._read = function(n) {
|
||||
|
||||
function push(fast) {
|
||||
assert(!pushedNull, 'push() after null push');
|
||||
- var c = pos >= data.length ? null : data.slice(pos, pos + n);
|
||||
+ var c;
|
||||
+ if (pos >= data.length)
|
||||
+ c = null;
|
||||
+ else {
|
||||
+ if (n + pos > data.length)
|
||||
+ n = data.length - pos;
|
||||
+ c = data.slice(pos, pos + n);
|
||||
+ }
|
||||
pushedNull = c === null;
|
||||
if (fast) {
|
||||
pos += n;
|
||||
diff --git a/test/simple/test-stream-writev.js b/test/simple/test-stream-writev.js
|
||||
index 5b49e6e..b5321f3 100644
|
||||
--- a/test/simple/test-stream-writev.js
|
||||
+++ b/test/simple/test-stream-writev.js
|
||||
@@ -22,7 +22,7 @@
|
||||
var common = require('../common');
|
||||
var assert = require('assert');
|
||||
|
||||
-var stream = require('stream');
|
||||
+var stream = require('../../');
|
||||
|
||||
var queue = [];
|
||||
for (var decode = 0; decode < 2; decode++) {
|
||||
diff --git a/test/simple/test-stream2-basic.js b/test/simple/test-stream2-basic.js
|
||||
index 3814bf0..248c1be 100644
|
||||
--- a/test/simple/test-stream2-basic.js
|
||||
+++ b/test/simple/test-stream2-basic.js
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
|
||||
var common = require('../common.js');
|
||||
-var R = require('_stream_readable');
|
||||
+var R = require('../../lib/_stream_readable');
|
||||
var assert = require('assert');
|
||||
|
||||
var util = require('util');
|
||||
diff --git a/test/simple/test-stream2-compatibility.js b/test/simple/test-stream2-compatibility.js
|
||||
index 6cdd4e9..f0fa84b 100644
|
||||
--- a/test/simple/test-stream2-compatibility.js
|
||||
+++ b/test/simple/test-stream2-compatibility.js
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
|
||||
var common = require('../common.js');
|
||||
-var R = require('_stream_readable');
|
||||
+var R = require('../../lib/_stream_readable');
|
||||
var assert = require('assert');
|
||||
|
||||
var util = require('util');
|
||||
diff --git a/test/simple/test-stream2-finish-pipe.js b/test/simple/test-stream2-finish-pipe.js
|
||||
index 39b274f..006a19b 100644
|
||||
--- a/test/simple/test-stream2-finish-pipe.js
|
||||
+++ b/test/simple/test-stream2-finish-pipe.js
|
||||
@@ -20,7 +20,7 @@
|
||||
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
var common = require('../common.js');
|
||||
-var stream = require('stream');
|
||||
+var stream = require('../../');
|
||||
var Buffer = require('buffer').Buffer;
|
||||
|
||||
var r = new stream.Readable();
|
||||
diff --git a/test/simple/test-stream2-fs.js b/test/simple/test-stream2-fs.js
|
||||
deleted file mode 100644
|
||||
index e162406..0000000
|
||||
--- a/test/simple/test-stream2-fs.js
|
||||
+++ /dev/null
|
||||
@@ -1,72 +0,0 @@
|
||||
-// Copyright Joyent, Inc. and other Node contributors.
|
||||
-//
|
||||
-// 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.
|
||||
-
|
||||
-
|
||||
-var common = require('../common.js');
|
||||
-var R = require('_stream_readable');
|
||||
-var assert = require('assert');
|
||||
-
|
||||
-var fs = require('fs');
|
||||
-var FSReadable = fs.ReadStream;
|
||||
-
|
||||
-var path = require('path');
|
||||
-var file = path.resolve(common.fixturesDir, 'x1024.txt');
|
||||
-
|
||||
-var size = fs.statSync(file).size;
|
||||
-
|
||||
-var expectLengths = [1024];
|
||||
-
|
||||
-var util = require('util');
|
||||
-var Stream = require('stream');
|
||||
-
|
||||
-util.inherits(TestWriter, Stream);
|
||||
-
|
||||
-function TestWriter() {
|
||||
- Stream.apply(this);
|
||||
- this.buffer = [];
|
||||
- this.length = 0;
|
||||
-}
|
||||
-
|
||||
-TestWriter.prototype.write = function(c) {
|
||||
- this.buffer.push(c.toString());
|
||||
- this.length += c.length;
|
||||
- return true;
|
||||
-};
|
||||
-
|
||||
-TestWriter.prototype.end = function(c) {
|
||||
- if (c) this.buffer.push(c.toString());
|
||||
- this.emit('results', this.buffer);
|
||||
-}
|
||||
-
|
||||
-var r = new FSReadable(file);
|
||||
-var w = new TestWriter();
|
||||
-
|
||||
-w.on('results', function(res) {
|
||||
- console.error(res, w.length);
|
||||
- assert.equal(w.length, size);
|
||||
- var l = 0;
|
||||
- assert.deepEqual(res.map(function (c) {
|
||||
- return c.length;
|
||||
- }), expectLengths);
|
||||
- console.log('ok');
|
||||
-});
|
||||
-
|
||||
-r.pipe(w);
|
||||
diff --git a/test/simple/test-stream2-httpclient-response-end.js b/test/simple/test-stream2-httpclient-response-end.js
|
||||
deleted file mode 100644
|
||||
index 15cffc2..0000000
|
||||
--- a/test/simple/test-stream2-httpclient-response-end.js
|
||||
+++ /dev/null
|
||||
@@ -1,52 +0,0 @@
|
||||
-// Copyright Joyent, Inc. and other Node contributors.
|
||||
-//
|
||||
-// 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.
|
||||
-
|
||||
-var common = require('../common.js');
|
||||
-var assert = require('assert');
|
||||
-var http = require('http');
|
||||
-var msg = 'Hello';
|
||||
-var readable_event = false;
|
||||
-var end_event = false;
|
||||
-var server = http.createServer(function(req, res) {
|
||||
- res.writeHead(200, {'Content-Type': 'text/plain'});
|
||||
- res.end(msg);
|
||||
-}).listen(common.PORT, function() {
|
||||
- http.get({port: common.PORT}, function(res) {
|
||||
- var data = '';
|
||||
- res.on('readable', function() {
|
||||
- console.log('readable event');
|
||||
- readable_event = true;
|
||||
- data += res.read();
|
||||
- });
|
||||
- res.on('end', function() {
|
||||
- console.log('end event');
|
||||
- end_event = true;
|
||||
- assert.strictEqual(msg, data);
|
||||
- server.close();
|
||||
- });
|
||||
- });
|
||||
-});
|
||||
-
|
||||
-process.on('exit', function() {
|
||||
- assert(readable_event);
|
||||
- assert(end_event);
|
||||
-});
|
||||
-
|
||||
diff --git a/test/simple/test-stream2-large-read-stall.js b/test/simple/test-stream2-large-read-stall.js
|
||||
index 2fbfbca..667985b 100644
|
||||
--- a/test/simple/test-stream2-large-read-stall.js
|
||||
+++ b/test/simple/test-stream2-large-read-stall.js
|
||||
@@ -30,7 +30,7 @@ var PUSHSIZE = 20;
|
||||
var PUSHCOUNT = 1000;
|
||||
var HWM = 50;
|
||||
|
||||
-var Readable = require('stream').Readable;
|
||||
+var Readable = require('../../').Readable;
|
||||
var r = new Readable({
|
||||
highWaterMark: HWM
|
||||
});
|
||||
@@ -39,23 +39,23 @@ var rs = r._readableState;
|
||||
r._read = push;
|
||||
|
||||
r.on('readable', function() {
|
||||
- console.error('>> readable');
|
||||
+ //console.error('>> readable');
|
||||
do {
|
||||
- console.error(' > read(%d)', READSIZE);
|
||||
+ //console.error(' > read(%d)', READSIZE);
|
||||
var ret = r.read(READSIZE);
|
||||
- console.error(' < %j (%d remain)', ret && ret.length, rs.length);
|
||||
+ //console.error(' < %j (%d remain)', ret && ret.length, rs.length);
|
||||
} while (ret && ret.length === READSIZE);
|
||||
|
||||
- console.error('<< after read()',
|
||||
- ret && ret.length,
|
||||
- rs.needReadable,
|
||||
- rs.length);
|
||||
+ //console.error('<< after read()',
|
||||
+ // ret && ret.length,
|
||||
+ // rs.needReadable,
|
||||
+ // rs.length);
|
||||
});
|
||||
|
||||
var endEmitted = false;
|
||||
r.on('end', function() {
|
||||
endEmitted = true;
|
||||
- console.error('end');
|
||||
+ //console.error('end');
|
||||
});
|
||||
|
||||
var pushes = 0;
|
||||
@@ -64,11 +64,11 @@ function push() {
|
||||
return;
|
||||
|
||||
if (pushes++ === PUSHCOUNT) {
|
||||
- console.error(' push(EOF)');
|
||||
+ //console.error(' push(EOF)');
|
||||
return r.push(null);
|
||||
}
|
||||
|
||||
- console.error(' push #%d', pushes);
|
||||
+ //console.error(' push #%d', pushes);
|
||||
if (r.push(new Buffer(PUSHSIZE)))
|
||||
setTimeout(push);
|
||||
}
|
||||
diff --git a/test/simple/test-stream2-objects.js b/test/simple/test-stream2-objects.js
|
||||
index 3e6931d..ff47d89 100644
|
||||
--- a/test/simple/test-stream2-objects.js
|
||||
+++ b/test/simple/test-stream2-objects.js
|
||||
@@ -21,8 +21,8 @@
|
||||
|
||||
|
||||
var common = require('../common.js');
|
||||
-var Readable = require('_stream_readable');
|
||||
-var Writable = require('_stream_writable');
|
||||
+var Readable = require('../../lib/_stream_readable');
|
||||
+var Writable = require('../../lib/_stream_writable');
|
||||
var assert = require('assert');
|
||||
|
||||
// tiny node-tap lookalike.
|
||||
diff --git a/test/simple/test-stream2-pipe-error-handling.js b/test/simple/test-stream2-pipe-error-handling.js
|
||||
index cf7531c..e3f3e4e 100644
|
||||
--- a/test/simple/test-stream2-pipe-error-handling.js
|
||||
+++ b/test/simple/test-stream2-pipe-error-handling.js
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
var common = require('../common');
|
||||
var assert = require('assert');
|
||||
-var stream = require('stream');
|
||||
+var stream = require('../../');
|
||||
|
||||
(function testErrorListenerCatches() {
|
||||
var count = 1000;
|
||||
diff --git a/test/simple/test-stream2-pipe-error-once-listener.js b/test/simple/test-stream2-pipe-error-once-listener.js
|
||||
index 5e8e3cb..53b2616 100755
|
||||
--- a/test/simple/test-stream2-pipe-error-once-listener.js
|
||||
+++ b/test/simple/test-stream2-pipe-error-once-listener.js
|
||||
@@ -24,7 +24,7 @@ var common = require('../common.js');
|
||||
var assert = require('assert');
|
||||
|
||||
var util = require('util');
|
||||
-var stream = require('stream');
|
||||
+var stream = require('../../');
|
||||
|
||||
|
||||
var Read = function() {
|
||||
diff --git a/test/simple/test-stream2-push.js b/test/simple/test-stream2-push.js
|
||||
index b63edc3..eb2b0e9 100644
|
||||
--- a/test/simple/test-stream2-push.js
|
||||
+++ b/test/simple/test-stream2-push.js
|
||||
@@ -20,7 +20,7 @@
|
||||
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
var common = require('../common.js');
|
||||
-var stream = require('stream');
|
||||
+var stream = require('../../');
|
||||
var Readable = stream.Readable;
|
||||
var Writable = stream.Writable;
|
||||
var assert = require('assert');
|
||||
diff --git a/test/simple/test-stream2-read-sync-stack.js b/test/simple/test-stream2-read-sync-stack.js
|
||||
index e8a7305..9740a47 100644
|
||||
--- a/test/simple/test-stream2-read-sync-stack.js
|
||||
+++ b/test/simple/test-stream2-read-sync-stack.js
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
var common = require('../common');
|
||||
var assert = require('assert');
|
||||
-var Readable = require('stream').Readable;
|
||||
+var Readable = require('../../').Readable;
|
||||
var r = new Readable();
|
||||
var N = 256 * 1024;
|
||||
|
||||
diff --git a/test/simple/test-stream2-readable-empty-buffer-no-eof.js b/test/simple/test-stream2-readable-empty-buffer-no-eof.js
|
||||
index cd30178..4b1659d 100644
|
||||
--- a/test/simple/test-stream2-readable-empty-buffer-no-eof.js
|
||||
+++ b/test/simple/test-stream2-readable-empty-buffer-no-eof.js
|
||||
@@ -22,10 +22,9 @@
|
||||
var common = require('../common');
|
||||
var assert = require('assert');
|
||||
|
||||
-var Readable = require('stream').Readable;
|
||||
+var Readable = require('../../').Readable;
|
||||
|
||||
test1();
|
||||
-test2();
|
||||
|
||||
function test1() {
|
||||
var r = new Readable();
|
||||
@@ -88,31 +87,3 @@ function test1() {
|
||||
console.log('ok');
|
||||
});
|
||||
}
|
||||
-
|
||||
-function test2() {
|
||||
- var r = new Readable({ encoding: 'base64' });
|
||||
- var reads = 5;
|
||||
- r._read = function(n) {
|
||||
- if (!reads--)
|
||||
- return r.push(null); // EOF
|
||||
- else
|
||||
- return r.push(new Buffer('x'));
|
||||
- };
|
||||
-
|
||||
- var results = [];
|
||||
- function flow() {
|
||||
- var chunk;
|
||||
- while (null !== (chunk = r.read()))
|
||||
- results.push(chunk + '');
|
||||
- }
|
||||
- r.on('readable', flow);
|
||||
- r.on('end', function() {
|
||||
- results.push('EOF');
|
||||
- });
|
||||
- flow();
|
||||
-
|
||||
- process.on('exit', function() {
|
||||
- assert.deepEqual(results, [ 'eHh4', 'eHg=', 'EOF' ]);
|
||||
- console.log('ok');
|
||||
- });
|
||||
-}
|
||||
diff --git a/test/simple/test-stream2-readable-from-list.js b/test/simple/test-stream2-readable-from-list.js
|
||||
index 7c96ffe..04a96f5 100644
|
||||
--- a/test/simple/test-stream2-readable-from-list.js
|
||||
+++ b/test/simple/test-stream2-readable-from-list.js
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
var assert = require('assert');
|
||||
var common = require('../common.js');
|
||||
-var fromList = require('_stream_readable')._fromList;
|
||||
+var fromList = require('../../lib/_stream_readable')._fromList;
|
||||
|
||||
// tiny node-tap lookalike.
|
||||
var tests = [];
|
||||
diff --git a/test/simple/test-stream2-readable-legacy-drain.js b/test/simple/test-stream2-readable-legacy-drain.js
|
||||
index 675da8e..51fd3d5 100644
|
||||
--- a/test/simple/test-stream2-readable-legacy-drain.js
|
||||
+++ b/test/simple/test-stream2-readable-legacy-drain.js
|
||||
@@ -22,7 +22,7 @@
|
||||
var common = require('../common');
|
||||
var assert = require('assert');
|
||||
|
||||
-var Stream = require('stream');
|
||||
+var Stream = require('../../');
|
||||
var Readable = Stream.Readable;
|
||||
|
||||
var r = new Readable();
|
||||
diff --git a/test/simple/test-stream2-readable-non-empty-end.js b/test/simple/test-stream2-readable-non-empty-end.js
|
||||
index 7314ae7..c971898 100644
|
||||
--- a/test/simple/test-stream2-readable-non-empty-end.js
|
||||
+++ b/test/simple/test-stream2-readable-non-empty-end.js
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
var assert = require('assert');
|
||||
var common = require('../common.js');
|
||||
-var Readable = require('_stream_readable');
|
||||
+var Readable = require('../../lib/_stream_readable');
|
||||
|
||||
var len = 0;
|
||||
var chunks = new Array(10);
|
||||
diff --git a/test/simple/test-stream2-readable-wrap-empty.js b/test/simple/test-stream2-readable-wrap-empty.js
|
||||
index 2e5cf25..fd8a3dc 100644
|
||||
--- a/test/simple/test-stream2-readable-wrap-empty.js
|
||||
+++ b/test/simple/test-stream2-readable-wrap-empty.js
|
||||
@@ -22,7 +22,7 @@
|
||||
var common = require('../common');
|
||||
var assert = require('assert');
|
||||
|
||||
-var Readable = require('_stream_readable');
|
||||
+var Readable = require('../../lib/_stream_readable');
|
||||
var EE = require('events').EventEmitter;
|
||||
|
||||
var oldStream = new EE();
|
||||
diff --git a/test/simple/test-stream2-readable-wrap.js b/test/simple/test-stream2-readable-wrap.js
|
||||
index 90eea01..6b177f7 100644
|
||||
--- a/test/simple/test-stream2-readable-wrap.js
|
||||
+++ b/test/simple/test-stream2-readable-wrap.js
|
||||
@@ -22,8 +22,8 @@
|
||||
var common = require('../common');
|
||||
var assert = require('assert');
|
||||
|
||||
-var Readable = require('_stream_readable');
|
||||
-var Writable = require('_stream_writable');
|
||||
+var Readable = require('../../lib/_stream_readable');
|
||||
+var Writable = require('../../lib/_stream_writable');
|
||||
var EE = require('events').EventEmitter;
|
||||
|
||||
var testRuns = 0, completedRuns = 0;
|
||||
diff --git a/test/simple/test-stream2-set-encoding.js b/test/simple/test-stream2-set-encoding.js
|
||||
index 5d2c32a..685531b 100644
|
||||
--- a/test/simple/test-stream2-set-encoding.js
|
||||
+++ b/test/simple/test-stream2-set-encoding.js
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
var common = require('../common.js');
|
||||
var assert = require('assert');
|
||||
-var R = require('_stream_readable');
|
||||
+var R = require('../../lib/_stream_readable');
|
||||
var util = require('util');
|
||||
|
||||
// tiny node-tap lookalike.
|
||||
diff --git a/test/simple/test-stream2-transform.js b/test/simple/test-stream2-transform.js
|
||||
index 9c9ddd8..a0cacc6 100644
|
||||
--- a/test/simple/test-stream2-transform.js
|
||||
+++ b/test/simple/test-stream2-transform.js
|
||||
@@ -21,8 +21,8 @@
|
||||
|
||||
var assert = require('assert');
|
||||
var common = require('../common.js');
|
||||
-var PassThrough = require('_stream_passthrough');
|
||||
-var Transform = require('_stream_transform');
|
||||
+var PassThrough = require('../../').PassThrough;
|
||||
+var Transform = require('../../').Transform;
|
||||
|
||||
// tiny node-tap lookalike.
|
||||
var tests = [];
|
||||
diff --git a/test/simple/test-stream2-unpipe-drain.js b/test/simple/test-stream2-unpipe-drain.js
|
||||
index d66dc3c..365b327 100644
|
||||
--- a/test/simple/test-stream2-unpipe-drain.js
|
||||
+++ b/test/simple/test-stream2-unpipe-drain.js
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
var common = require('../common.js');
|
||||
var assert = require('assert');
|
||||
-var stream = require('stream');
|
||||
+var stream = require('../../');
|
||||
var crypto = require('crypto');
|
||||
|
||||
var util = require('util');
|
||||
diff --git a/test/simple/test-stream2-unpipe-leak.js b/test/simple/test-stream2-unpipe-leak.js
|
||||
index 99f8746..17c92ae 100644
|
||||
--- a/test/simple/test-stream2-unpipe-leak.js
|
||||
+++ b/test/simple/test-stream2-unpipe-leak.js
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
var common = require('../common.js');
|
||||
var assert = require('assert');
|
||||
-var stream = require('stream');
|
||||
+var stream = require('../../');
|
||||
|
||||
var chunk = new Buffer('hallo');
|
||||
|
||||
diff --git a/test/simple/test-stream2-writable.js b/test/simple/test-stream2-writable.js
|
||||
index 704100c..209c3a6 100644
|
||||
--- a/test/simple/test-stream2-writable.js
|
||||
+++ b/test/simple/test-stream2-writable.js
|
||||
@@ -20,8 +20,8 @@
|
||||
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
var common = require('../common.js');
|
||||
-var W = require('_stream_writable');
|
||||
-var D = require('_stream_duplex');
|
||||
+var W = require('../../').Writable;
|
||||
+var D = require('../../').Duplex;
|
||||
var assert = require('assert');
|
||||
|
||||
var util = require('util');
|
||||
diff --git a/test/simple/test-stream3-pause-then-read.js b/test/simple/test-stream3-pause-then-read.js
|
||||
index b91bde3..2f72c15 100644
|
||||
--- a/test/simple/test-stream3-pause-then-read.js
|
||||
+++ b/test/simple/test-stream3-pause-then-read.js
|
||||
@@ -22,7 +22,7 @@
|
||||
var common = require('../common');
|
||||
var assert = require('assert');
|
||||
|
||||
-var stream = require('stream');
|
||||
+var stream = require('../../');
|
||||
var Readable = stream.Readable;
|
||||
var Writable = stream.Writable;
|
||||
|
89
node_modules/streamroller/node_modules/readable-stream/lib/_stream_duplex.js
generated
vendored
Normal file
89
node_modules/streamroller/node_modules/readable-stream/lib/_stream_duplex.js
generated
vendored
Normal file
@ -0,0 +1,89 @@
|
||||
// Copyright Joyent, Inc. and other Node contributors.
|
||||
//
|
||||
// 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.
|
||||
|
||||
// a duplex stream is just a stream that is both readable and writable.
|
||||
// Since JS doesn't have multiple prototypal inheritance, this class
|
||||
// prototypally inherits from Readable, and then parasitically from
|
||||
// Writable.
|
||||
|
||||
module.exports = Duplex;
|
||||
|
||||
/*<replacement>*/
|
||||
var objectKeys = Object.keys || function (obj) {
|
||||
var keys = [];
|
||||
for (var key in obj) keys.push(key);
|
||||
return keys;
|
||||
}
|
||||
/*</replacement>*/
|
||||
|
||||
|
||||
/*<replacement>*/
|
||||
var util = require('core-util-is');
|
||||
util.inherits = require('inherits');
|
||||
/*</replacement>*/
|
||||
|
||||
var Readable = require('./_stream_readable');
|
||||
var Writable = require('./_stream_writable');
|
||||
|
||||
util.inherits(Duplex, Readable);
|
||||
|
||||
forEach(objectKeys(Writable.prototype), function(method) {
|
||||
if (!Duplex.prototype[method])
|
||||
Duplex.prototype[method] = Writable.prototype[method];
|
||||
});
|
||||
|
||||
function Duplex(options) {
|
||||
if (!(this instanceof Duplex))
|
||||
return new Duplex(options);
|
||||
|
||||
Readable.call(this, options);
|
||||
Writable.call(this, options);
|
||||
|
||||
if (options && options.readable === false)
|
||||
this.readable = false;
|
||||
|
||||
if (options && options.writable === false)
|
||||
this.writable = false;
|
||||
|
||||
this.allowHalfOpen = true;
|
||||
if (options && options.allowHalfOpen === false)
|
||||
this.allowHalfOpen = false;
|
||||
|
||||
this.once('end', onend);
|
||||
}
|
||||
|
||||
// the no-half-open enforcer
|
||||
function onend() {
|
||||
// if we allow half-open state, or if the writable side ended,
|
||||
// then we're ok.
|
||||
if (this.allowHalfOpen || this._writableState.ended)
|
||||
return;
|
||||
|
||||
// no more data can be written.
|
||||
// But allow more writes to happen in this tick.
|
||||
process.nextTick(this.end.bind(this));
|
||||
}
|
||||
|
||||
function forEach (xs, f) {
|
||||
for (var i = 0, l = xs.length; i < l; i++) {
|
||||
f(xs[i], i);
|
||||
}
|
||||
}
|
46
node_modules/streamroller/node_modules/readable-stream/lib/_stream_passthrough.js
generated
vendored
Normal file
46
node_modules/streamroller/node_modules/readable-stream/lib/_stream_passthrough.js
generated
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
// Copyright Joyent, Inc. and other Node contributors.
|
||||
//
|
||||
// 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.
|
||||
|
||||
// a passthrough stream.
|
||||
// basically just the most minimal sort of Transform stream.
|
||||
// Every written chunk gets output as-is.
|
||||
|
||||
module.exports = PassThrough;
|
||||
|
||||
var Transform = require('./_stream_transform');
|
||||
|
||||
/*<replacement>*/
|
||||
var util = require('core-util-is');
|
||||
util.inherits = require('inherits');
|
||||
/*</replacement>*/
|
||||
|
||||
util.inherits(PassThrough, Transform);
|
||||
|
||||
function PassThrough(options) {
|
||||
if (!(this instanceof PassThrough))
|
||||
return new PassThrough(options);
|
||||
|
||||
Transform.call(this, options);
|
||||
}
|
||||
|
||||
PassThrough.prototype._transform = function(chunk, encoding, cb) {
|
||||
cb(null, chunk);
|
||||
};
|
951
node_modules/streamroller/node_modules/readable-stream/lib/_stream_readable.js
generated
vendored
Normal file
951
node_modules/streamroller/node_modules/readable-stream/lib/_stream_readable.js
generated
vendored
Normal file
@ -0,0 +1,951 @@
|
||||
// Copyright Joyent, Inc. and other Node contributors.
|
||||
//
|
||||
// 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.
|
||||
|
||||
module.exports = Readable;
|
||||
|
||||
/*<replacement>*/
|
||||
var isArray = require('isarray');
|
||||
/*</replacement>*/
|
||||
|
||||
|
||||
/*<replacement>*/
|
||||
var Buffer = require('buffer').Buffer;
|
||||
/*</replacement>*/
|
||||
|
||||
Readable.ReadableState = ReadableState;
|
||||
|
||||
var EE = require('events').EventEmitter;
|
||||
|
||||
/*<replacement>*/
|
||||
if (!EE.listenerCount) EE.listenerCount = function(emitter, type) {
|
||||
return emitter.listeners(type).length;
|
||||
};
|
||||
/*</replacement>*/
|
||||
|
||||
var Stream = require('stream');
|
||||
|
||||
/*<replacement>*/
|
||||
var util = require('core-util-is');
|
||||
util.inherits = require('inherits');
|
||||
/*</replacement>*/
|
||||
|
||||
var StringDecoder;
|
||||
|
||||
|
||||
/*<replacement>*/
|
||||
var debug = require('util');
|
||||
if (debug && debug.debuglog) {
|
||||
debug = debug.debuglog('stream');
|
||||
} else {
|
||||
debug = function () {};
|
||||
}
|
||||
/*</replacement>*/
|
||||
|
||||
|
||||
util.inherits(Readable, Stream);
|
||||
|
||||
function ReadableState(options, stream) {
|
||||
var Duplex = require('./_stream_duplex');
|
||||
|
||||
options = options || {};
|
||||
|
||||
// the point at which it stops calling _read() to fill the buffer
|
||||
// Note: 0 is a valid value, means "don't call _read preemptively ever"
|
||||
var hwm = options.highWaterMark;
|
||||
var defaultHwm = options.objectMode ? 16 : 16 * 1024;
|
||||
this.highWaterMark = (hwm || hwm === 0) ? hwm : defaultHwm;
|
||||
|
||||
// cast to ints.
|
||||
this.highWaterMark = ~~this.highWaterMark;
|
||||
|
||||
this.buffer = [];
|
||||
this.length = 0;
|
||||
this.pipes = null;
|
||||
this.pipesCount = 0;
|
||||
this.flowing = null;
|
||||
this.ended = false;
|
||||
this.endEmitted = false;
|
||||
this.reading = false;
|
||||
|
||||
// a flag to be able to tell if the onwrite cb is called immediately,
|
||||
// or on a later tick. We set this to true at first, because any
|
||||
// actions that shouldn't happen until "later" should generally also
|
||||
// not happen before the first write call.
|
||||
this.sync = true;
|
||||
|
||||
// whenever we return null, then we set a flag to say
|
||||
// that we're awaiting a 'readable' event emission.
|
||||
this.needReadable = false;
|
||||
this.emittedReadable = false;
|
||||
this.readableListening = false;
|
||||
|
||||
|
||||
// object stream flag. Used to make read(n) ignore n and to
|
||||
// make all the buffer merging and length checks go away
|
||||
this.objectMode = !!options.objectMode;
|
||||
|
||||
if (stream instanceof Duplex)
|
||||
this.objectMode = this.objectMode || !!options.readableObjectMode;
|
||||
|
||||
// Crypto is kind of old and crusty. Historically, its default string
|
||||
// encoding is 'binary' so we have to make this configurable.
|
||||
// Everything else in the universe uses 'utf8', though.
|
||||
this.defaultEncoding = options.defaultEncoding || 'utf8';
|
||||
|
||||
// when piping, we only care about 'readable' events that happen
|
||||
// after read()ing all the bytes and not getting any pushback.
|
||||
this.ranOut = false;
|
||||
|
||||
// the number of writers that are awaiting a drain event in .pipe()s
|
||||
this.awaitDrain = 0;
|
||||
|
||||
// if true, a maybeReadMore has been scheduled
|
||||
this.readingMore = false;
|
||||
|
||||
this.decoder = null;
|
||||
this.encoding = null;
|
||||
if (options.encoding) {
|
||||
if (!StringDecoder)
|
||||
StringDecoder = require('string_decoder/').StringDecoder;
|
||||
this.decoder = new StringDecoder(options.encoding);
|
||||
this.encoding = options.encoding;
|
||||
}
|
||||
}
|
||||
|
||||
function Readable(options) {
|
||||
var Duplex = require('./_stream_duplex');
|
||||
|
||||
if (!(this instanceof Readable))
|
||||
return new Readable(options);
|
||||
|
||||
this._readableState = new ReadableState(options, this);
|
||||
|
||||
// legacy
|
||||
this.readable = true;
|
||||
|
||||
Stream.call(this);
|
||||
}
|
||||
|
||||
// Manually shove something into the read() buffer.
|
||||
// This returns true if the highWaterMark has not been hit yet,
|
||||
// similar to how Writable.write() returns true if you should
|
||||
// write() some more.
|
||||
Readable.prototype.push = function(chunk, encoding) {
|
||||
var state = this._readableState;
|
||||
|
||||
if (util.isString(chunk) && !state.objectMode) {
|
||||
encoding = encoding || state.defaultEncoding;
|
||||
if (encoding !== state.encoding) {
|
||||
chunk = new Buffer(chunk, encoding);
|
||||
encoding = '';
|
||||
}
|
||||
}
|
||||
|
||||
return readableAddChunk(this, state, chunk, encoding, false);
|
||||
};
|
||||
|
||||
// Unshift should *always* be something directly out of read()
|
||||
Readable.prototype.unshift = function(chunk) {
|
||||
var state = this._readableState;
|
||||
return readableAddChunk(this, state, chunk, '', true);
|
||||
};
|
||||
|
||||
function readableAddChunk(stream, state, chunk, encoding, addToFront) {
|
||||
var er = chunkInvalid(state, chunk);
|
||||
if (er) {
|
||||
stream.emit('error', er);
|
||||
} else if (util.isNullOrUndefined(chunk)) {
|
||||
state.reading = false;
|
||||
if (!state.ended)
|
||||
onEofChunk(stream, state);
|
||||
} else if (state.objectMode || chunk && chunk.length > 0) {
|
||||
if (state.ended && !addToFront) {
|
||||
var e = new Error('stream.push() after EOF');
|
||||
stream.emit('error', e);
|
||||
} else if (state.endEmitted && addToFront) {
|
||||
var e = new Error('stream.unshift() after end event');
|
||||
stream.emit('error', e);
|
||||
} else {
|
||||
if (state.decoder && !addToFront && !encoding)
|
||||
chunk = state.decoder.write(chunk);
|
||||
|
||||
if (!addToFront)
|
||||
state.reading = false;
|
||||
|
||||
// if we want the data now, just emit it.
|
||||
if (state.flowing && state.length === 0 && !state.sync) {
|
||||
stream.emit('data', chunk);
|
||||
stream.read(0);
|
||||
} else {
|
||||
// update the buffer info.
|
||||
state.length += state.objectMode ? 1 : chunk.length;
|
||||
if (addToFront)
|
||||
state.buffer.unshift(chunk);
|
||||
else
|
||||
state.buffer.push(chunk);
|
||||
|
||||
if (state.needReadable)
|
||||
emitReadable(stream);
|
||||
}
|
||||
|
||||
maybeReadMore(stream, state);
|
||||
}
|
||||
} else if (!addToFront) {
|
||||
state.reading = false;
|
||||
}
|
||||
|
||||
return needMoreData(state);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// if it's past the high water mark, we can push in some more.
|
||||
// Also, if we have no data yet, we can stand some
|
||||
// more bytes. This is to work around cases where hwm=0,
|
||||
// such as the repl. Also, if the push() triggered a
|
||||
// readable event, and the user called read(largeNumber) such that
|
||||
// needReadable was set, then we ought to push more, so that another
|
||||
// 'readable' event will be triggered.
|
||||
function needMoreData(state) {
|
||||
return !state.ended &&
|
||||
(state.needReadable ||
|
||||
state.length < state.highWaterMark ||
|
||||
state.length === 0);
|
||||
}
|
||||
|
||||
// backwards compatibility.
|
||||
Readable.prototype.setEncoding = function(enc) {
|
||||
if (!StringDecoder)
|
||||
StringDecoder = require('string_decoder/').StringDecoder;
|
||||
this._readableState.decoder = new StringDecoder(enc);
|
||||
this._readableState.encoding = enc;
|
||||
return this;
|
||||
};
|
||||
|
||||
// Don't raise the hwm > 128MB
|
||||
var MAX_HWM = 0x800000;
|
||||
function roundUpToNextPowerOf2(n) {
|
||||
if (n >= MAX_HWM) {
|
||||
n = MAX_HWM;
|
||||
} else {
|
||||
// Get the next highest power of 2
|
||||
n--;
|
||||
for (var p = 1; p < 32; p <<= 1) n |= n >> p;
|
||||
n++;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
function howMuchToRead(n, state) {
|
||||
if (state.length === 0 && state.ended)
|
||||
return 0;
|
||||
|
||||
if (state.objectMode)
|
||||
return n === 0 ? 0 : 1;
|
||||
|
||||
if (isNaN(n) || util.isNull(n)) {
|
||||
// only flow one buffer at a time
|
||||
if (state.flowing && state.buffer.length)
|
||||
return state.buffer[0].length;
|
||||
else
|
||||
return state.length;
|
||||
}
|
||||
|
||||
if (n <= 0)
|
||||
return 0;
|
||||
|
||||
// If we're asking for more than the target buffer level,
|
||||
// then raise the water mark. Bump up to the next highest
|
||||
// power of 2, to prevent increasing it excessively in tiny
|
||||
// amounts.
|
||||
if (n > state.highWaterMark)
|
||||
state.highWaterMark = roundUpToNextPowerOf2(n);
|
||||
|
||||
// don't have that much. return null, unless we've ended.
|
||||
if (n > state.length) {
|
||||
if (!state.ended) {
|
||||
state.needReadable = true;
|
||||
return 0;
|
||||
} else
|
||||
return state.length;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
// you can override either this method, or the async _read(n) below.
|
||||
Readable.prototype.read = function(n) {
|
||||
debug('read', n);
|
||||
var state = this._readableState;
|
||||
var nOrig = n;
|
||||
|
||||
if (!util.isNumber(n) || n > 0)
|
||||
state.emittedReadable = false;
|
||||
|
||||
// if we're doing read(0) to trigger a readable event, but we
|
||||
// already have a bunch of data in the buffer, then just trigger
|
||||
// the 'readable' event and move on.
|
||||
if (n === 0 &&
|
||||
state.needReadable &&
|
||||
(state.length >= state.highWaterMark || state.ended)) {
|
||||
debug('read: emitReadable', state.length, state.ended);
|
||||
if (state.length === 0 && state.ended)
|
||||
endReadable(this);
|
||||
else
|
||||
emitReadable(this);
|
||||
return null;
|
||||
}
|
||||
|
||||
n = howMuchToRead(n, state);
|
||||
|
||||
// if we've ended, and we're now clear, then finish it up.
|
||||
if (n === 0 && state.ended) {
|
||||
if (state.length === 0)
|
||||
endReadable(this);
|
||||
return null;
|
||||
}
|
||||
|
||||
// All the actual chunk generation logic needs to be
|
||||
// *below* the call to _read. The reason is that in certain
|
||||
// synthetic stream cases, such as passthrough streams, _read
|
||||
// may be a completely synchronous operation which may change
|
||||
// the state of the read buffer, providing enough data when
|
||||
// before there was *not* enough.
|
||||
//
|
||||
// So, the steps are:
|
||||
// 1. Figure out what the state of things will be after we do
|
||||
// a read from the buffer.
|
||||
//
|
||||
// 2. If that resulting state will trigger a _read, then call _read.
|
||||
// Note that this may be asynchronous, or synchronous. Yes, it is
|
||||
// deeply ugly to write APIs this way, but that still doesn't mean
|
||||
// that the Readable class should behave improperly, as streams are
|
||||
// designed to be sync/async agnostic.
|
||||
// Take note if the _read call is sync or async (ie, if the read call
|
||||
// has returned yet), so that we know whether or not it's safe to emit
|
||||
// 'readable' etc.
|
||||
//
|
||||
// 3. Actually pull the requested chunks out of the buffer and return.
|
||||
|
||||
// if we need a readable event, then we need to do some reading.
|
||||
var doRead = state.needReadable;
|
||||
debug('need readable', doRead);
|
||||
|
||||
// if we currently have less than the highWaterMark, then also read some
|
||||
if (state.length === 0 || state.length - n < state.highWaterMark) {
|
||||
doRead = true;
|
||||
debug('length less than watermark', doRead);
|
||||
}
|
||||
|
||||
// however, if we've ended, then there's no point, and if we're already
|
||||
// reading, then it's unnecessary.
|
||||
if (state.ended || state.reading) {
|
||||
doRead = false;
|
||||
debug('reading or ended', doRead);
|
||||
}
|
||||
|
||||
if (doRead) {
|
||||
debug('do read');
|
||||
state.reading = true;
|
||||
state.sync = true;
|
||||
// if the length is currently zero, then we *need* a readable event.
|
||||
if (state.length === 0)
|
||||
state.needReadable = true;
|
||||
// call internal read method
|
||||
this._read(state.highWaterMark);
|
||||
state.sync = false;
|
||||
}
|
||||
|
||||
// If _read pushed data synchronously, then `reading` will be false,
|
||||
// and we need to re-evaluate how much data we can return to the user.
|
||||
if (doRead && !state.reading)
|
||||
n = howMuchToRead(nOrig, state);
|
||||
|
||||
var ret;
|
||||
if (n > 0)
|
||||
ret = fromList(n, state);
|
||||
else
|
||||
ret = null;
|
||||
|
||||
if (util.isNull(ret)) {
|
||||
state.needReadable = true;
|
||||
n = 0;
|
||||
}
|
||||
|
||||
state.length -= n;
|
||||
|
||||
// If we have nothing in the buffer, then we want to know
|
||||
// as soon as we *do* get something into the buffer.
|
||||
if (state.length === 0 && !state.ended)
|
||||
state.needReadable = true;
|
||||
|
||||
// If we tried to read() past the EOF, then emit end on the next tick.
|
||||
if (nOrig !== n && state.ended && state.length === 0)
|
||||
endReadable(this);
|
||||
|
||||
if (!util.isNull(ret))
|
||||
this.emit('data', ret);
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
function chunkInvalid(state, chunk) {
|
||||
var er = null;
|
||||
if (!util.isBuffer(chunk) &&
|
||||
!util.isString(chunk) &&
|
||||
!util.isNullOrUndefined(chunk) &&
|
||||
!state.objectMode) {
|
||||
er = new TypeError('Invalid non-string/buffer chunk');
|
||||
}
|
||||
return er;
|
||||
}
|
||||
|
||||
|
||||
function onEofChunk(stream, state) {
|
||||
if (state.decoder && !state.ended) {
|
||||
var chunk = state.decoder.end();
|
||||
if (chunk && chunk.length) {
|
||||
state.buffer.push(chunk);
|
||||
state.length += state.objectMode ? 1 : chunk.length;
|
||||
}
|
||||
}
|
||||
state.ended = true;
|
||||
|
||||
// emit 'readable' now to make sure it gets picked up.
|
||||
emitReadable(stream);
|
||||
}
|
||||
|
||||
// Don't emit readable right away in sync mode, because this can trigger
|
||||
// another read() call => stack overflow. This way, it might trigger
|
||||
// a nextTick recursion warning, but that's not so bad.
|
||||
function emitReadable(stream) {
|
||||
var state = stream._readableState;
|
||||
state.needReadable = false;
|
||||
if (!state.emittedReadable) {
|
||||
debug('emitReadable', state.flowing);
|
||||
state.emittedReadable = true;
|
||||
if (state.sync)
|
||||
process.nextTick(function() {
|
||||
emitReadable_(stream);
|
||||
});
|
||||
else
|
||||
emitReadable_(stream);
|
||||
}
|
||||
}
|
||||
|
||||
function emitReadable_(stream) {
|
||||
debug('emit readable');
|
||||
stream.emit('readable');
|
||||
flow(stream);
|
||||
}
|
||||
|
||||
|
||||
// at this point, the user has presumably seen the 'readable' event,
|
||||
// and called read() to consume some data. that may have triggered
|
||||
// in turn another _read(n) call, in which case reading = true if
|
||||
// it's in progress.
|
||||
// However, if we're not ended, or reading, and the length < hwm,
|
||||
// then go ahead and try to read some more preemptively.
|
||||
function maybeReadMore(stream, state) {
|
||||
if (!state.readingMore) {
|
||||
state.readingMore = true;
|
||||
process.nextTick(function() {
|
||||
maybeReadMore_(stream, state);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function maybeReadMore_(stream, state) {
|
||||
var len = state.length;
|
||||
while (!state.reading && !state.flowing && !state.ended &&
|
||||
state.length < state.highWaterMark) {
|
||||
debug('maybeReadMore read 0');
|
||||
stream.read(0);
|
||||
if (len === state.length)
|
||||
// didn't get any data, stop spinning.
|
||||
break;
|
||||
else
|
||||
len = state.length;
|
||||
}
|
||||
state.readingMore = false;
|
||||
}
|
||||
|
||||
// abstract method. to be overridden in specific implementation classes.
|
||||
// call cb(er, data) where data is <= n in length.
|
||||
// for virtual (non-string, non-buffer) streams, "length" is somewhat
|
||||
// arbitrary, and perhaps not very meaningful.
|
||||
Readable.prototype._read = function(n) {
|
||||
this.emit('error', new Error('not implemented'));
|
||||
};
|
||||
|
||||
Readable.prototype.pipe = function(dest, pipeOpts) {
|
||||
var src = this;
|
||||
var state = this._readableState;
|
||||
|
||||
switch (state.pipesCount) {
|
||||
case 0:
|
||||
state.pipes = dest;
|
||||
break;
|
||||
case 1:
|
||||
state.pipes = [state.pipes, dest];
|
||||
break;
|
||||
default:
|
||||
state.pipes.push(dest);
|
||||
break;
|
||||
}
|
||||
state.pipesCount += 1;
|
||||
debug('pipe count=%d opts=%j', state.pipesCount, pipeOpts);
|
||||
|
||||
var doEnd = (!pipeOpts || pipeOpts.end !== false) &&
|
||||
dest !== process.stdout &&
|
||||
dest !== process.stderr;
|
||||
|
||||
var endFn = doEnd ? onend : cleanup;
|
||||
if (state.endEmitted)
|
||||
process.nextTick(endFn);
|
||||
else
|
||||
src.once('end', endFn);
|
||||
|
||||
dest.on('unpipe', onunpipe);
|
||||
function onunpipe(readable) {
|
||||
debug('onunpipe');
|
||||
if (readable === src) {
|
||||
cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
function onend() {
|
||||
debug('onend');
|
||||
dest.end();
|
||||
}
|
||||
|
||||
// when the dest drains, it reduces the awaitDrain counter
|
||||
// on the source. This would be more elegant with a .once()
|
||||
// handler in flow(), but adding and removing repeatedly is
|
||||
// too slow.
|
||||
var ondrain = pipeOnDrain(src);
|
||||
dest.on('drain', ondrain);
|
||||
|
||||
function cleanup() {
|
||||
debug('cleanup');
|
||||
// cleanup event handlers once the pipe is broken
|
||||
dest.removeListener('close', onclose);
|
||||
dest.removeListener('finish', onfinish);
|
||||
dest.removeListener('drain', ondrain);
|
||||
dest.removeListener('error', onerror);
|
||||
dest.removeListener('unpipe', onunpipe);
|
||||
src.removeListener('end', onend);
|
||||
src.removeListener('end', cleanup);
|
||||
src.removeListener('data', ondata);
|
||||
|
||||
// if the reader is waiting for a drain event from this
|
||||
// specific writer, then it would cause it to never start
|
||||
// flowing again.
|
||||
// So, if this is awaiting a drain, then we just call it now.
|
||||
// If we don't know, then assume that we are waiting for one.
|
||||
if (state.awaitDrain &&
|
||||
(!dest._writableState || dest._writableState.needDrain))
|
||||
ondrain();
|
||||
}
|
||||
|
||||
src.on('data', ondata);
|
||||
function ondata(chunk) {
|
||||
debug('ondata');
|
||||
var ret = dest.write(chunk);
|
||||
if (false === ret) {
|
||||
debug('false write response, pause',
|
||||
src._readableState.awaitDrain);
|
||||
src._readableState.awaitDrain++;
|
||||
src.pause();
|
||||
}
|
||||
}
|
||||
|
||||
// if the dest has an error, then stop piping into it.
|
||||
// however, don't suppress the throwing behavior for this.
|
||||
function onerror(er) {
|
||||
debug('onerror', er);
|
||||
unpipe();
|
||||
dest.removeListener('error', onerror);
|
||||
if (EE.listenerCount(dest, 'error') === 0)
|
||||
dest.emit('error', er);
|
||||
}
|
||||
// This is a brutally ugly hack to make sure that our error handler
|
||||
// is attached before any userland ones. NEVER DO THIS.
|
||||
if (!dest._events || !dest._events.error)
|
||||
dest.on('error', onerror);
|
||||
else if (isArray(dest._events.error))
|
||||
dest._events.error.unshift(onerror);
|
||||
else
|
||||
dest._events.error = [onerror, dest._events.error];
|
||||
|
||||
|
||||
|
||||
// Both close and finish should trigger unpipe, but only once.
|
||||
function onclose() {
|
||||
dest.removeListener('finish', onfinish);
|
||||
unpipe();
|
||||
}
|
||||
dest.once('close', onclose);
|
||||
function onfinish() {
|
||||
debug('onfinish');
|
||||
dest.removeListener('close', onclose);
|
||||
unpipe();
|
||||
}
|
||||
dest.once('finish', onfinish);
|
||||
|
||||
function unpipe() {
|
||||
debug('unpipe');
|
||||
src.unpipe(dest);
|
||||
}
|
||||
|
||||
// tell the dest that it's being piped to
|
||||
dest.emit('pipe', src);
|
||||
|
||||
// start the flow if it hasn't been started already.
|
||||
if (!state.flowing) {
|
||||
debug('pipe resume');
|
||||
src.resume();
|
||||
}
|
||||
|
||||
return dest;
|
||||
};
|
||||
|
||||
function pipeOnDrain(src) {
|
||||
return function() {
|
||||
var state = src._readableState;
|
||||
debug('pipeOnDrain', state.awaitDrain);
|
||||
if (state.awaitDrain)
|
||||
state.awaitDrain--;
|
||||
if (state.awaitDrain === 0 && EE.listenerCount(src, 'data')) {
|
||||
state.flowing = true;
|
||||
flow(src);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Readable.prototype.unpipe = function(dest) {
|
||||
var state = this._readableState;
|
||||
|
||||
// if we're not piping anywhere, then do nothing.
|
||||
if (state.pipesCount === 0)
|
||||
return this;
|
||||
|
||||
// just one destination. most common case.
|
||||
if (state.pipesCount === 1) {
|
||||
// passed in one, but it's not the right one.
|
||||
if (dest && dest !== state.pipes)
|
||||
return this;
|
||||
|
||||
if (!dest)
|
||||
dest = state.pipes;
|
||||
|
||||
// got a match.
|
||||
state.pipes = null;
|
||||
state.pipesCount = 0;
|
||||
state.flowing = false;
|
||||
if (dest)
|
||||
dest.emit('unpipe', this);
|
||||
return this;
|
||||
}
|
||||
|
||||
// slow case. multiple pipe destinations.
|
||||
|
||||
if (!dest) {
|
||||
// remove all.
|
||||
var dests = state.pipes;
|
||||
var len = state.pipesCount;
|
||||
state.pipes = null;
|
||||
state.pipesCount = 0;
|
||||
state.flowing = false;
|
||||
|
||||
for (var i = 0; i < len; i++)
|
||||
dests[i].emit('unpipe', this);
|
||||
return this;
|
||||
}
|
||||
|
||||
// try to find the right one.
|
||||
var i = indexOf(state.pipes, dest);
|
||||
if (i === -1)
|
||||
return this;
|
||||
|
||||
state.pipes.splice(i, 1);
|
||||
state.pipesCount -= 1;
|
||||
if (state.pipesCount === 1)
|
||||
state.pipes = state.pipes[0];
|
||||
|
||||
dest.emit('unpipe', this);
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
// set up data events if they are asked for
|
||||
// Ensure readable listeners eventually get something
|
||||
Readable.prototype.on = function(ev, fn) {
|
||||
var res = Stream.prototype.on.call(this, ev, fn);
|
||||
|
||||
// If listening to data, and it has not explicitly been paused,
|
||||
// then call resume to start the flow of data on the next tick.
|
||||
if (ev === 'data' && false !== this._readableState.flowing) {
|
||||
this.resume();
|
||||
}
|
||||
|
||||
if (ev === 'readable' && this.readable) {
|
||||
var state = this._readableState;
|
||||
if (!state.readableListening) {
|
||||
state.readableListening = true;
|
||||
state.emittedReadable = false;
|
||||
state.needReadable = true;
|
||||
if (!state.reading) {
|
||||
var self = this;
|
||||
process.nextTick(function() {
|
||||
debug('readable nexttick read 0');
|
||||
self.read(0);
|
||||
});
|
||||
} else if (state.length) {
|
||||
emitReadable(this, state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
};
|
||||
Readable.prototype.addListener = Readable.prototype.on;
|
||||
|
||||
// pause() and resume() are remnants of the legacy readable stream API
|
||||
// If the user uses them, then switch into old mode.
|
||||
Readable.prototype.resume = function() {
|
||||
var state = this._readableState;
|
||||
if (!state.flowing) {
|
||||
debug('resume');
|
||||
state.flowing = true;
|
||||
if (!state.reading) {
|
||||
debug('resume read 0');
|
||||
this.read(0);
|
||||
}
|
||||
resume(this, state);
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
function resume(stream, state) {
|
||||
if (!state.resumeScheduled) {
|
||||
state.resumeScheduled = true;
|
||||
process.nextTick(function() {
|
||||
resume_(stream, state);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function resume_(stream, state) {
|
||||
state.resumeScheduled = false;
|
||||
stream.emit('resume');
|
||||
flow(stream);
|
||||
if (state.flowing && !state.reading)
|
||||
stream.read(0);
|
||||
}
|
||||
|
||||
Readable.prototype.pause = function() {
|
||||
debug('call pause flowing=%j', this._readableState.flowing);
|
||||
if (false !== this._readableState.flowing) {
|
||||
debug('pause');
|
||||
this._readableState.flowing = false;
|
||||
this.emit('pause');
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
function flow(stream) {
|
||||
var state = stream._readableState;
|
||||
debug('flow', state.flowing);
|
||||
if (state.flowing) {
|
||||
do {
|
||||
var chunk = stream.read();
|
||||
} while (null !== chunk && state.flowing);
|
||||
}
|
||||
}
|
||||
|
||||
// wrap an old-style stream as the async data source.
|
||||
// This is *not* part of the readable stream interface.
|
||||
// It is an ugly unfortunate mess of history.
|
||||
Readable.prototype.wrap = function(stream) {
|
||||
var state = this._readableState;
|
||||
var paused = false;
|
||||
|
||||
var self = this;
|
||||
stream.on('end', function() {
|
||||
debug('wrapped end');
|
||||
if (state.decoder && !state.ended) {
|
||||
var chunk = state.decoder.end();
|
||||
if (chunk && chunk.length)
|
||||
self.push(chunk);
|
||||
}
|
||||
|
||||
self.push(null);
|
||||
});
|
||||
|
||||
stream.on('data', function(chunk) {
|
||||
debug('wrapped data');
|
||||
if (state.decoder)
|
||||
chunk = state.decoder.write(chunk);
|
||||
if (!chunk || !state.objectMode && !chunk.length)
|
||||
return;
|
||||
|
||||
var ret = self.push(chunk);
|
||||
if (!ret) {
|
||||
paused = true;
|
||||
stream.pause();
|
||||
}
|
||||
});
|
||||
|
||||
// proxy all the other methods.
|
||||
// important when wrapping filters and duplexes.
|
||||
for (var i in stream) {
|
||||
if (util.isFunction(stream[i]) && util.isUndefined(this[i])) {
|
||||
this[i] = function(method) { return function() {
|
||||
return stream[method].apply(stream, arguments);
|
||||
}}(i);
|
||||
}
|
||||
}
|
||||
|
||||
// proxy certain important events.
|
||||
var events = ['error', 'close', 'destroy', 'pause', 'resume'];
|
||||
forEach(events, function(ev) {
|
||||
stream.on(ev, self.emit.bind(self, ev));
|
||||
});
|
||||
|
||||
// when we try to consume some more bytes, simply unpause the
|
||||
// underlying stream.
|
||||
self._read = function(n) {
|
||||
debug('wrapped _read', n);
|
||||
if (paused) {
|
||||
paused = false;
|
||||
stream.resume();
|
||||
}
|
||||
};
|
||||
|
||||
return self;
|
||||
};
|
||||
|
||||
|
||||
|
||||
// exposed for testing purposes only.
|
||||
Readable._fromList = fromList;
|
||||
|
||||
// Pluck off n bytes from an array of buffers.
|
||||
// Length is the combined lengths of all the buffers in the list.
|
||||
function fromList(n, state) {
|
||||
var list = state.buffer;
|
||||
var length = state.length;
|
||||
var stringMode = !!state.decoder;
|
||||
var objectMode = !!state.objectMode;
|
||||
var ret;
|
||||
|
||||
// nothing in the list, definitely empty.
|
||||
if (list.length === 0)
|
||||
return null;
|
||||
|
||||
if (length === 0)
|
||||
ret = null;
|
||||
else if (objectMode)
|
||||
ret = list.shift();
|
||||
else if (!n || n >= length) {
|
||||
// read it all, truncate the array.
|
||||
if (stringMode)
|
||||
ret = list.join('');
|
||||
else
|
||||
ret = Buffer.concat(list, length);
|
||||
list.length = 0;
|
||||
} else {
|
||||
// read just some of it.
|
||||
if (n < list[0].length) {
|
||||
// just take a part of the first list item.
|
||||
// slice is the same for buffers and strings.
|
||||
var buf = list[0];
|
||||
ret = buf.slice(0, n);
|
||||
list[0] = buf.slice(n);
|
||||
} else if (n === list[0].length) {
|
||||
// first list is a perfect match
|
||||
ret = list.shift();
|
||||
} else {
|
||||
// complex case.
|
||||
// we have enough to cover it, but it spans past the first buffer.
|
||||
if (stringMode)
|
||||
ret = '';
|
||||
else
|
||||
ret = new Buffer(n);
|
||||
|
||||
var c = 0;
|
||||
for (var i = 0, l = list.length; i < l && c < n; i++) {
|
||||
var buf = list[0];
|
||||
var cpy = Math.min(n - c, buf.length);
|
||||
|
||||
if (stringMode)
|
||||
ret += buf.slice(0, cpy);
|
||||
else
|
||||
buf.copy(ret, c, 0, cpy);
|
||||
|
||||
if (cpy < buf.length)
|
||||
list[0] = buf.slice(cpy);
|
||||
else
|
||||
list.shift();
|
||||
|
||||
c += cpy;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
function endReadable(stream) {
|
||||
var state = stream._readableState;
|
||||
|
||||
// If we get here before consuming all the bytes, then that is a
|
||||
// bug in node. Should never happen.
|
||||
if (state.length > 0)
|
||||
throw new Error('endReadable called on non-empty stream');
|
||||
|
||||
if (!state.endEmitted) {
|
||||
state.ended = true;
|
||||
process.nextTick(function() {
|
||||
// Check that we didn't get one last unshift.
|
||||
if (!state.endEmitted && state.length === 0) {
|
||||
state.endEmitted = true;
|
||||
stream.readable = false;
|
||||
stream.emit('end');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function forEach (xs, f) {
|
||||
for (var i = 0, l = xs.length; i < l; i++) {
|
||||
f(xs[i], i);
|
||||
}
|
||||
}
|
||||
|
||||
function indexOf (xs, x) {
|
||||
for (var i = 0, l = xs.length; i < l; i++) {
|
||||
if (xs[i] === x) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
209
node_modules/streamroller/node_modules/readable-stream/lib/_stream_transform.js
generated
vendored
Normal file
209
node_modules/streamroller/node_modules/readable-stream/lib/_stream_transform.js
generated
vendored
Normal file
@ -0,0 +1,209 @@
|
||||
// Copyright Joyent, Inc. and other Node contributors.
|
||||
//
|
||||
// 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.
|
||||
|
||||
|
||||
// a transform stream is a readable/writable stream where you do
|
||||
// something with the data. Sometimes it's called a "filter",
|
||||
// but that's not a great name for it, since that implies a thing where
|
||||
// some bits pass through, and others are simply ignored. (That would
|
||||
// be a valid example of a transform, of course.)
|
||||
//
|
||||
// While the output is causally related to the input, it's not a
|
||||
// necessarily symmetric or synchronous transformation. For example,
|
||||
// a zlib stream might take multiple plain-text writes(), and then
|
||||
// emit a single compressed chunk some time in the future.
|
||||
//
|
||||
// Here's how this works:
|
||||
//
|
||||
// The Transform stream has all the aspects of the readable and writable
|
||||
// stream classes. When you write(chunk), that calls _write(chunk,cb)
|
||||
// internally, and returns false if there's a lot of pending writes
|
||||
// buffered up. When you call read(), that calls _read(n) until
|
||||
// there's enough pending readable data buffered up.
|
||||
//
|
||||
// In a transform stream, the written data is placed in a buffer. When
|
||||
// _read(n) is called, it transforms the queued up data, calling the
|
||||
// buffered _write cb's as it consumes chunks. If consuming a single
|
||||
// written chunk would result in multiple output chunks, then the first
|
||||
// outputted bit calls the readcb, and subsequent chunks just go into
|
||||
// the read buffer, and will cause it to emit 'readable' if necessary.
|
||||
//
|
||||
// This way, back-pressure is actually determined by the reading side,
|
||||
// since _read has to be called to start processing a new chunk. However,
|
||||
// a pathological inflate type of transform can cause excessive buffering
|
||||
// here. For example, imagine a stream where every byte of input is
|
||||
// interpreted as an integer from 0-255, and then results in that many
|
||||
// bytes of output. Writing the 4 bytes {ff,ff,ff,ff} would result in
|
||||
// 1kb of data being output. In this case, you could write a very small
|
||||
// amount of input, and end up with a very large amount of output. In
|
||||
// such a pathological inflating mechanism, there'd be no way to tell
|
||||
// the system to stop doing the transform. A single 4MB write could
|
||||
// cause the system to run out of memory.
|
||||
//
|
||||
// However, even in such a pathological case, only a single written chunk
|
||||
// would be consumed, and then the rest would wait (un-transformed) until
|
||||
// the results of the previous transformed chunk were consumed.
|
||||
|
||||
module.exports = Transform;
|
||||
|
||||
var Duplex = require('./_stream_duplex');
|
||||
|
||||
/*<replacement>*/
|
||||
var util = require('core-util-is');
|
||||
util.inherits = require('inherits');
|
||||
/*</replacement>*/
|
||||
|
||||
util.inherits(Transform, Duplex);
|
||||
|
||||
|
||||
function TransformState(options, stream) {
|
||||
this.afterTransform = function(er, data) {
|
||||
return afterTransform(stream, er, data);
|
||||
};
|
||||
|
||||
this.needTransform = false;
|
||||
this.transforming = false;
|
||||
this.writecb = null;
|
||||
this.writechunk = null;
|
||||
}
|
||||
|
||||
function afterTransform(stream, er, data) {
|
||||
var ts = stream._transformState;
|
||||
ts.transforming = false;
|
||||
|
||||
var cb = ts.writecb;
|
||||
|
||||
if (!cb)
|
||||
return stream.emit('error', new Error('no writecb in Transform class'));
|
||||
|
||||
ts.writechunk = null;
|
||||
ts.writecb = null;
|
||||
|
||||
if (!util.isNullOrUndefined(data))
|
||||
stream.push(data);
|
||||
|
||||
if (cb)
|
||||
cb(er);
|
||||
|
||||
var rs = stream._readableState;
|
||||
rs.reading = false;
|
||||
if (rs.needReadable || rs.length < rs.highWaterMark) {
|
||||
stream._read(rs.highWaterMark);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function Transform(options) {
|
||||
if (!(this instanceof Transform))
|
||||
return new Transform(options);
|
||||
|
||||
Duplex.call(this, options);
|
||||
|
||||
this._transformState = new TransformState(options, this);
|
||||
|
||||
// when the writable side finishes, then flush out anything remaining.
|
||||
var stream = this;
|
||||
|
||||
// start out asking for a readable event once data is transformed.
|
||||
this._readableState.needReadable = true;
|
||||
|
||||
// we have implemented the _read method, and done the other things
|
||||
// that Readable wants before the first _read call, so unset the
|
||||
// sync guard flag.
|
||||
this._readableState.sync = false;
|
||||
|
||||
this.once('prefinish', function() {
|
||||
if (util.isFunction(this._flush))
|
||||
this._flush(function(er) {
|
||||
done(stream, er);
|
||||
});
|
||||
else
|
||||
done(stream);
|
||||
});
|
||||
}
|
||||
|
||||
Transform.prototype.push = function(chunk, encoding) {
|
||||
this._transformState.needTransform = false;
|
||||
return Duplex.prototype.push.call(this, chunk, encoding);
|
||||
};
|
||||
|
||||
// This is the part where you do stuff!
|
||||
// override this function in implementation classes.
|
||||
// 'chunk' is an input chunk.
|
||||
//
|
||||
// Call `push(newChunk)` to pass along transformed output
|
||||
// to the readable side. You may call 'push' zero or more times.
|
||||
//
|
||||
// Call `cb(err)` when you are done with this chunk. If you pass
|
||||
// an error, then that'll put the hurt on the whole operation. If you
|
||||
// never call cb(), then you'll never get another chunk.
|
||||
Transform.prototype._transform = function(chunk, encoding, cb) {
|
||||
throw new Error('not implemented');
|
||||
};
|
||||
|
||||
Transform.prototype._write = function(chunk, encoding, cb) {
|
||||
var ts = this._transformState;
|
||||
ts.writecb = cb;
|
||||
ts.writechunk = chunk;
|
||||
ts.writeencoding = encoding;
|
||||
if (!ts.transforming) {
|
||||
var rs = this._readableState;
|
||||
if (ts.needTransform ||
|
||||
rs.needReadable ||
|
||||
rs.length < rs.highWaterMark)
|
||||
this._read(rs.highWaterMark);
|
||||
}
|
||||
};
|
||||
|
||||
// Doesn't matter what the args are here.
|
||||
// _transform does all the work.
|
||||
// That we got here means that the readable side wants more data.
|
||||
Transform.prototype._read = function(n) {
|
||||
var ts = this._transformState;
|
||||
|
||||
if (!util.isNull(ts.writechunk) && ts.writecb && !ts.transforming) {
|
||||
ts.transforming = true;
|
||||
this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform);
|
||||
} else {
|
||||
// mark that we need a transform, so that any data that comes in
|
||||
// will get processed, now that we've asked for it.
|
||||
ts.needTransform = true;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
function done(stream, er) {
|
||||
if (er)
|
||||
return stream.emit('error', er);
|
||||
|
||||
// if there's nothing in the write buffer, then that means
|
||||
// that nothing more will ever be provided
|
||||
var ws = stream._writableState;
|
||||
var ts = stream._transformState;
|
||||
|
||||
if (ws.length)
|
||||
throw new Error('calling transform done when ws.length != 0');
|
||||
|
||||
if (ts.transforming)
|
||||
throw new Error('calling transform done when still transforming');
|
||||
|
||||
return stream.push(null);
|
||||
}
|
477
node_modules/streamroller/node_modules/readable-stream/lib/_stream_writable.js
generated
vendored
Normal file
477
node_modules/streamroller/node_modules/readable-stream/lib/_stream_writable.js
generated
vendored
Normal file
@ -0,0 +1,477 @@
|
||||
// Copyright Joyent, Inc. and other Node contributors.
|
||||
//
|
||||
// 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.
|
||||
|
||||
// A bit simpler than readable streams.
|
||||
// Implement an async ._write(chunk, cb), and it'll handle all
|
||||
// the drain event emission and buffering.
|
||||
|
||||
module.exports = Writable;
|
||||
|
||||
/*<replacement>*/
|
||||
var Buffer = require('buffer').Buffer;
|
||||
/*</replacement>*/
|
||||
|
||||
Writable.WritableState = WritableState;
|
||||
|
||||
|
||||
/*<replacement>*/
|
||||
var util = require('core-util-is');
|
||||
util.inherits = require('inherits');
|
||||
/*</replacement>*/
|
||||
|
||||
var Stream = require('stream');
|
||||
|
||||
util.inherits(Writable, Stream);
|
||||
|
||||
function WriteReq(chunk, encoding, cb) {
|
||||
this.chunk = chunk;
|
||||
this.encoding = encoding;
|
||||
this.callback = cb;
|
||||
}
|
||||
|
||||
function WritableState(options, stream) {
|
||||
var Duplex = require('./_stream_duplex');
|
||||
|
||||
options = options || {};
|
||||
|
||||
// the point at which write() starts returning false
|
||||
// Note: 0 is a valid value, means that we always return false if
|
||||
// the entire buffer is not flushed immediately on write()
|
||||
var hwm = options.highWaterMark;
|
||||
var defaultHwm = options.objectMode ? 16 : 16 * 1024;
|
||||
this.highWaterMark = (hwm || hwm === 0) ? hwm : defaultHwm;
|
||||
|
||||
// object stream flag to indicate whether or not this stream
|
||||
// contains buffers or objects.
|
||||
this.objectMode = !!options.objectMode;
|
||||
|
||||
if (stream instanceof Duplex)
|
||||
this.objectMode = this.objectMode || !!options.writableObjectMode;
|
||||
|
||||
// cast to ints.
|
||||
this.highWaterMark = ~~this.highWaterMark;
|
||||
|
||||
this.needDrain = false;
|
||||
// at the start of calling end()
|
||||
this.ending = false;
|
||||
// when end() has been called, and returned
|
||||
this.ended = false;
|
||||
// when 'finish' is emitted
|
||||
this.finished = false;
|
||||
|
||||
// should we decode strings into buffers before passing to _write?
|
||||
// this is here so that some node-core streams can optimize string
|
||||
// handling at a lower level.
|
||||
var noDecode = options.decodeStrings === false;
|
||||
this.decodeStrings = !noDecode;
|
||||
|
||||
// Crypto is kind of old and crusty. Historically, its default string
|
||||
// encoding is 'binary' so we have to make this configurable.
|
||||
// Everything else in the universe uses 'utf8', though.
|
||||
this.defaultEncoding = options.defaultEncoding || 'utf8';
|
||||
|
||||
// not an actual buffer we keep track of, but a measurement
|
||||
// of how much we're waiting to get pushed to some underlying
|
||||
// socket or file.
|
||||
this.length = 0;
|
||||
|
||||
// a flag to see when we're in the middle of a write.
|
||||
this.writing = false;
|
||||
|
||||
// when true all writes will be buffered until .uncork() call
|
||||
this.corked = 0;
|
||||
|
||||
// a flag to be able to tell if the onwrite cb is called immediately,
|
||||
// or on a later tick. We set this to true at first, because any
|
||||
// actions that shouldn't happen until "later" should generally also
|
||||
// not happen before the first write call.
|
||||
this.sync = true;
|
||||
|
||||
// a flag to know if we're processing previously buffered items, which
|
||||
// may call the _write() callback in the same tick, so that we don't
|
||||
// end up in an overlapped onwrite situation.
|
||||
this.bufferProcessing = false;
|
||||
|
||||
// the callback that's passed to _write(chunk,cb)
|
||||
this.onwrite = function(er) {
|
||||
onwrite(stream, er);
|
||||
};
|
||||
|
||||
// the callback that the user supplies to write(chunk,encoding,cb)
|
||||
this.writecb = null;
|
||||
|
||||
// the amount that is being written when _write is called.
|
||||
this.writelen = 0;
|
||||
|
||||
this.buffer = [];
|
||||
|
||||
// number of pending user-supplied write callbacks
|
||||
// this must be 0 before 'finish' can be emitted
|
||||
this.pendingcb = 0;
|
||||
|
||||
// emit prefinish if the only thing we're waiting for is _write cbs
|
||||
// This is relevant for synchronous Transform streams
|
||||
this.prefinished = false;
|
||||
|
||||
// True if the error was already emitted and should not be thrown again
|
||||
this.errorEmitted = false;
|
||||
}
|
||||
|
||||
function Writable(options) {
|
||||
var Duplex = require('./_stream_duplex');
|
||||
|
||||
// Writable ctor is applied to Duplexes, though they're not
|
||||
// instanceof Writable, they're instanceof Readable.
|
||||
if (!(this instanceof Writable) && !(this instanceof Duplex))
|
||||
return new Writable(options);
|
||||
|
||||
this._writableState = new WritableState(options, this);
|
||||
|
||||
// legacy.
|
||||
this.writable = true;
|
||||
|
||||
Stream.call(this);
|
||||
}
|
||||
|
||||
// Otherwise people can pipe Writable streams, which is just wrong.
|
||||
Writable.prototype.pipe = function() {
|
||||
this.emit('error', new Error('Cannot pipe. Not readable.'));
|
||||
};
|
||||
|
||||
|
||||
function writeAfterEnd(stream, state, cb) {
|
||||
var er = new Error('write after end');
|
||||
// TODO: defer error events consistently everywhere, not just the cb
|
||||
stream.emit('error', er);
|
||||
process.nextTick(function() {
|
||||
cb(er);
|
||||
});
|
||||
}
|
||||
|
||||
// If we get something that is not a buffer, string, null, or undefined,
|
||||
// and we're not in objectMode, then that's an error.
|
||||
// Otherwise stream chunks are all considered to be of length=1, and the
|
||||
// watermarks determine how many objects to keep in the buffer, rather than
|
||||
// how many bytes or characters.
|
||||
function validChunk(stream, state, chunk, cb) {
|
||||
var valid = true;
|
||||
if (!util.isBuffer(chunk) &&
|
||||
!util.isString(chunk) &&
|
||||
!util.isNullOrUndefined(chunk) &&
|
||||
!state.objectMode) {
|
||||
var er = new TypeError('Invalid non-string/buffer chunk');
|
||||
stream.emit('error', er);
|
||||
process.nextTick(function() {
|
||||
cb(er);
|
||||
});
|
||||
valid = false;
|
||||
}
|
||||
return valid;
|
||||
}
|
||||
|
||||
Writable.prototype.write = function(chunk, encoding, cb) {
|
||||
var state = this._writableState;
|
||||
var ret = false;
|
||||
|
||||
if (util.isFunction(encoding)) {
|
||||
cb = encoding;
|
||||
encoding = null;
|
||||
}
|
||||
|
||||
if (util.isBuffer(chunk))
|
||||
encoding = 'buffer';
|
||||
else if (!encoding)
|
||||
encoding = state.defaultEncoding;
|
||||
|
||||
if (!util.isFunction(cb))
|
||||
cb = function() {};
|
||||
|
||||
if (state.ended)
|
||||
writeAfterEnd(this, state, cb);
|
||||
else if (validChunk(this, state, chunk, cb)) {
|
||||
state.pendingcb++;
|
||||
ret = writeOrBuffer(this, state, chunk, encoding, cb);
|
||||
}
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
Writable.prototype.cork = function() {
|
||||
var state = this._writableState;
|
||||
|
||||
state.corked++;
|
||||
};
|
||||
|
||||
Writable.prototype.uncork = function() {
|
||||
var state = this._writableState;
|
||||
|
||||
if (state.corked) {
|
||||
state.corked--;
|
||||
|
||||
if (!state.writing &&
|
||||
!state.corked &&
|
||||
!state.finished &&
|
||||
!state.bufferProcessing &&
|
||||
state.buffer.length)
|
||||
clearBuffer(this, state);
|
||||
}
|
||||
};
|
||||
|
||||
function decodeChunk(state, chunk, encoding) {
|
||||
if (!state.objectMode &&
|
||||
state.decodeStrings !== false &&
|
||||
util.isString(chunk)) {
|
||||
chunk = new Buffer(chunk, encoding);
|
||||
}
|
||||
return chunk;
|
||||
}
|
||||
|
||||
// if we're already writing something, then just put this
|
||||
// in the queue, and wait our turn. Otherwise, call _write
|
||||
// If we return false, then we need a drain event, so set that flag.
|
||||
function writeOrBuffer(stream, state, chunk, encoding, cb) {
|
||||
chunk = decodeChunk(state, chunk, encoding);
|
||||
if (util.isBuffer(chunk))
|
||||
encoding = 'buffer';
|
||||
var len = state.objectMode ? 1 : chunk.length;
|
||||
|
||||
state.length += len;
|
||||
|
||||
var ret = state.length < state.highWaterMark;
|
||||
// we must ensure that previous needDrain will not be reset to false.
|
||||
if (!ret)
|
||||
state.needDrain = true;
|
||||
|
||||
if (state.writing || state.corked)
|
||||
state.buffer.push(new WriteReq(chunk, encoding, cb));
|
||||
else
|
||||
doWrite(stream, state, false, len, chunk, encoding, cb);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
function doWrite(stream, state, writev, len, chunk, encoding, cb) {
|
||||
state.writelen = len;
|
||||
state.writecb = cb;
|
||||
state.writing = true;
|
||||
state.sync = true;
|
||||
if (writev)
|
||||
stream._writev(chunk, state.onwrite);
|
||||
else
|
||||
stream._write(chunk, encoding, state.onwrite);
|
||||
state.sync = false;
|
||||
}
|
||||
|
||||
function onwriteError(stream, state, sync, er, cb) {
|
||||
if (sync)
|
||||
process.nextTick(function() {
|
||||
state.pendingcb--;
|
||||
cb(er);
|
||||
});
|
||||
else {
|
||||
state.pendingcb--;
|
||||
cb(er);
|
||||
}
|
||||
|
||||
stream._writableState.errorEmitted = true;
|
||||
stream.emit('error', er);
|
||||
}
|
||||
|
||||
function onwriteStateUpdate(state) {
|
||||
state.writing = false;
|
||||
state.writecb = null;
|
||||
state.length -= state.writelen;
|
||||
state.writelen = 0;
|
||||
}
|
||||
|
||||
function onwrite(stream, er) {
|
||||
var state = stream._writableState;
|
||||
var sync = state.sync;
|
||||
var cb = state.writecb;
|
||||
|
||||
onwriteStateUpdate(state);
|
||||
|
||||
if (er)
|
||||
onwriteError(stream, state, sync, er, cb);
|
||||
else {
|
||||
// Check if we're actually ready to finish, but don't emit yet
|
||||
var finished = needFinish(stream, state);
|
||||
|
||||
if (!finished &&
|
||||
!state.corked &&
|
||||
!state.bufferProcessing &&
|
||||
state.buffer.length) {
|
||||
clearBuffer(stream, state);
|
||||
}
|
||||
|
||||
if (sync) {
|
||||
process.nextTick(function() {
|
||||
afterWrite(stream, state, finished, cb);
|
||||
});
|
||||
} else {
|
||||
afterWrite(stream, state, finished, cb);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function afterWrite(stream, state, finished, cb) {
|
||||
if (!finished)
|
||||
onwriteDrain(stream, state);
|
||||
state.pendingcb--;
|
||||
cb();
|
||||
finishMaybe(stream, state);
|
||||
}
|
||||
|
||||
// Must force callback to be called on nextTick, so that we don't
|
||||
// emit 'drain' before the write() consumer gets the 'false' return
|
||||
// value, and has a chance to attach a 'drain' listener.
|
||||
function onwriteDrain(stream, state) {
|
||||
if (state.length === 0 && state.needDrain) {
|
||||
state.needDrain = false;
|
||||
stream.emit('drain');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// if there's something in the buffer waiting, then process it
|
||||
function clearBuffer(stream, state) {
|
||||
state.bufferProcessing = true;
|
||||
|
||||
if (stream._writev && state.buffer.length > 1) {
|
||||
// Fast case, write everything using _writev()
|
||||
var cbs = [];
|
||||
for (var c = 0; c < state.buffer.length; c++)
|
||||
cbs.push(state.buffer[c].callback);
|
||||
|
||||
// count the one we are adding, as well.
|
||||
// TODO(isaacs) clean this up
|
||||
state.pendingcb++;
|
||||
doWrite(stream, state, true, state.length, state.buffer, '', function(err) {
|
||||
for (var i = 0; i < cbs.length; i++) {
|
||||
state.pendingcb--;
|
||||
cbs[i](err);
|
||||
}
|
||||
});
|
||||
|
||||
// Clear buffer
|
||||
state.buffer = [];
|
||||
} else {
|
||||
// Slow case, write chunks one-by-one
|
||||
for (var c = 0; c < state.buffer.length; c++) {
|
||||
var entry = state.buffer[c];
|
||||
var chunk = entry.chunk;
|
||||
var encoding = entry.encoding;
|
||||
var cb = entry.callback;
|
||||
var len = state.objectMode ? 1 : chunk.length;
|
||||
|
||||
doWrite(stream, state, false, len, chunk, encoding, cb);
|
||||
|
||||
// if we didn't call the onwrite immediately, then
|
||||
// it means that we need to wait until it does.
|
||||
// also, that means that the chunk and cb are currently
|
||||
// being processed, so move the buffer counter past them.
|
||||
if (state.writing) {
|
||||
c++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (c < state.buffer.length)
|
||||
state.buffer = state.buffer.slice(c);
|
||||
else
|
||||
state.buffer.length = 0;
|
||||
}
|
||||
|
||||
state.bufferProcessing = false;
|
||||
}
|
||||
|
||||
Writable.prototype._write = function(chunk, encoding, cb) {
|
||||
cb(new Error('not implemented'));
|
||||
|
||||
};
|
||||
|
||||
Writable.prototype._writev = null;
|
||||
|
||||
Writable.prototype.end = function(chunk, encoding, cb) {
|
||||
var state = this._writableState;
|
||||
|
||||
if (util.isFunction(chunk)) {
|
||||
cb = chunk;
|
||||
chunk = null;
|
||||
encoding = null;
|
||||
} else if (util.isFunction(encoding)) {
|
||||
cb = encoding;
|
||||
encoding = null;
|
||||
}
|
||||
|
||||
if (!util.isNullOrUndefined(chunk))
|
||||
this.write(chunk, encoding);
|
||||
|
||||
// .end() fully uncorks
|
||||
if (state.corked) {
|
||||
state.corked = 1;
|
||||
this.uncork();
|
||||
}
|
||||
|
||||
// ignore unnecessary end() calls.
|
||||
if (!state.ending && !state.finished)
|
||||
endWritable(this, state, cb);
|
||||
};
|
||||
|
||||
|
||||
function needFinish(stream, state) {
|
||||
return (state.ending &&
|
||||
state.length === 0 &&
|
||||
!state.finished &&
|
||||
!state.writing);
|
||||
}
|
||||
|
||||
function prefinish(stream, state) {
|
||||
if (!state.prefinished) {
|
||||
state.prefinished = true;
|
||||
stream.emit('prefinish');
|
||||
}
|
||||
}
|
||||
|
||||
function finishMaybe(stream, state) {
|
||||
var need = needFinish(stream, state);
|
||||
if (need) {
|
||||
if (state.pendingcb === 0) {
|
||||
prefinish(stream, state);
|
||||
state.finished = true;
|
||||
stream.emit('finish');
|
||||
} else
|
||||
prefinish(stream, state);
|
||||
}
|
||||
return need;
|
||||
}
|
||||
|
||||
function endWritable(stream, state, cb) {
|
||||
state.ending = true;
|
||||
finishMaybe(stream, state);
|
||||
if (cb) {
|
||||
if (state.finished)
|
||||
process.nextTick(cb);
|
||||
else
|
||||
stream.once('finish', cb);
|
||||
}
|
||||
state.ended = true;
|
||||
}
|
112
node_modules/streamroller/node_modules/readable-stream/package.json
generated
vendored
Normal file
112
node_modules/streamroller/node_modules/readable-stream/package.json
generated
vendored
Normal file
@ -0,0 +1,112 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
{
|
||||
"raw": "readable-stream@^1.1.7",
|
||||
"scope": null,
|
||||
"escapedName": "readable-stream",
|
||||
"name": "readable-stream",
|
||||
"rawSpec": "^1.1.7",
|
||||
"spec": ">=1.1.7 <2.0.0",
|
||||
"type": "range"
|
||||
},
|
||||
"/home/burchettm/statsbot/node_modules/streamroller"
|
||||
]
|
||||
],
|
||||
"_from": "readable-stream@>=1.1.7 <2.0.0",
|
||||
"_id": "readable-stream@1.1.14",
|
||||
"_inCache": true,
|
||||
"_location": "/streamroller/readable-stream",
|
||||
"_nodeVersion": "5.10.1",
|
||||
"_npmOperationalInternal": {
|
||||
"host": "packages-16-east.internal.npmjs.com",
|
||||
"tmp": "tmp/readable-stream-1.1.14.tgz_1460563293219_0.5682175166439265"
|
||||
},
|
||||
"_npmUser": {
|
||||
"name": "cwmma",
|
||||
"email": "calvin.metcalf@gmail.com"
|
||||
},
|
||||
"_npmVersion": "3.8.3",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"raw": "readable-stream@^1.1.7",
|
||||
"scope": null,
|
||||
"escapedName": "readable-stream",
|
||||
"name": "readable-stream",
|
||||
"rawSpec": "^1.1.7",
|
||||
"spec": ">=1.1.7 <2.0.0",
|
||||
"type": "range"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/streamroller"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz",
|
||||
"_shasum": "7cf4c54ef648e3813084c636dd2079e166c081d9",
|
||||
"_shrinkwrap": null,
|
||||
"_spec": "readable-stream@^1.1.7",
|
||||
"_where": "/home/burchettm/statsbot/node_modules/streamroller",
|
||||
"author": {
|
||||
"name": "Isaac Z. Schlueter",
|
||||
"email": "i@izs.me",
|
||||
"url": "http://blog.izs.me/"
|
||||
},
|
||||
"browser": {
|
||||
"util": false
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/isaacs/readable-stream/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"core-util-is": "~1.0.0",
|
||||
"inherits": "~2.0.1",
|
||||
"isarray": "0.0.1",
|
||||
"string_decoder": "~0.10.x"
|
||||
},
|
||||
"description": "Streams3, a user-land copy of the stream library from Node.js v0.11.x",
|
||||
"devDependencies": {
|
||||
"tap": "~0.2.6"
|
||||
},
|
||||
"directories": {},
|
||||
"dist": {
|
||||
"shasum": "7cf4c54ef648e3813084c636dd2079e166c081d9",
|
||||
"tarball": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz"
|
||||
},
|
||||
"gitHead": "52550840cb1d6e8a98ef9a909a4bea360bc6f7da",
|
||||
"homepage": "https://github.com/isaacs/readable-stream#readme",
|
||||
"keywords": [
|
||||
"readable",
|
||||
"stream",
|
||||
"pipe"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "readable.js",
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "isaacs",
|
||||
"email": "isaacs@npmjs.com"
|
||||
},
|
||||
{
|
||||
"name": "tootallnate",
|
||||
"email": "nathan@tootallnate.net"
|
||||
},
|
||||
{
|
||||
"name": "rvagg",
|
||||
"email": "rod@vagg.org"
|
||||
},
|
||||
{
|
||||
"name": "cwmma",
|
||||
"email": "calvin.metcalf@gmail.com"
|
||||
}
|
||||
],
|
||||
"name": "readable-stream",
|
||||
"optionalDependencies": {},
|
||||
"readme": "ERROR: No README data found!",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/isaacs/readable-stream.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "tap test/simple/*.js"
|
||||
},
|
||||
"version": "1.1.14"
|
||||
}
|
1
node_modules/streamroller/node_modules/readable-stream/passthrough.js
generated
vendored
Normal file
1
node_modules/streamroller/node_modules/readable-stream/passthrough.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
module.exports = require("./lib/_stream_passthrough.js")
|
10
node_modules/streamroller/node_modules/readable-stream/readable.js
generated
vendored
Normal file
10
node_modules/streamroller/node_modules/readable-stream/readable.js
generated
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
exports = module.exports = require('./lib/_stream_readable.js');
|
||||
exports.Stream = require('stream');
|
||||
exports.Readable = exports;
|
||||
exports.Writable = require('./lib/_stream_writable.js');
|
||||
exports.Duplex = require('./lib/_stream_duplex.js');
|
||||
exports.Transform = require('./lib/_stream_transform.js');
|
||||
exports.PassThrough = require('./lib/_stream_passthrough.js');
|
||||
if (!process.browser && process.env.READABLE_STREAM === 'disable') {
|
||||
module.exports = require('stream');
|
||||
}
|
1
node_modules/streamroller/node_modules/readable-stream/transform.js
generated
vendored
Normal file
1
node_modules/streamroller/node_modules/readable-stream/transform.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
module.exports = require("./lib/_stream_transform.js")
|
1
node_modules/streamroller/node_modules/readable-stream/writable.js
generated
vendored
Normal file
1
node_modules/streamroller/node_modules/readable-stream/writable.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
module.exports = require("./lib/_stream_writable.js")
|
110
node_modules/streamroller/package.json
generated
vendored
Normal file
110
node_modules/streamroller/package.json
generated
vendored
Normal file
@ -0,0 +1,110 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
{
|
||||
"raw": "streamroller@^0.4.0",
|
||||
"scope": null,
|
||||
"escapedName": "streamroller",
|
||||
"name": "streamroller",
|
||||
"rawSpec": "^0.4.0",
|
||||
"spec": ">=0.4.0 <0.5.0",
|
||||
"type": "range"
|
||||
},
|
||||
"/home/burchettm/statsbot/node_modules/log4js"
|
||||
]
|
||||
],
|
||||
"_from": "streamroller@>=0.4.0 <0.5.0",
|
||||
"_id": "streamroller@0.4.0",
|
||||
"_inCache": true,
|
||||
"_location": "/streamroller",
|
||||
"_nodeVersion": "6.9.4",
|
||||
"_npmOperationalInternal": {
|
||||
"host": "packages-18-east.internal.npmjs.com",
|
||||
"tmp": "tmp/streamroller-0.4.0.tgz_1488230366735_0.8600998979527503"
|
||||
},
|
||||
"_npmUser": {
|
||||
"name": "csausdev",
|
||||
"email": "gareth.nomiddlename@gmail.com"
|
||||
},
|
||||
"_npmVersion": "3.10.10",
|
||||
"_phantomChildren": {
|
||||
"core-util-is": "1.0.2",
|
||||
"inherits": "2.0.3",
|
||||
"isarray": "0.0.1",
|
||||
"string_decoder": "0.10.31"
|
||||
},
|
||||
"_requested": {
|
||||
"raw": "streamroller@^0.4.0",
|
||||
"scope": null,
|
||||
"escapedName": "streamroller",
|
||||
"name": "streamroller",
|
||||
"rawSpec": "^0.4.0",
|
||||
"spec": ">=0.4.0 <0.5.0",
|
||||
"type": "range"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/log4js"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/streamroller/-/streamroller-0.4.0.tgz",
|
||||
"_shasum": "a273f1f91994549a2ddd112ccaa2d1dd23cb758c",
|
||||
"_shrinkwrap": null,
|
||||
"_spec": "streamroller@^0.4.0",
|
||||
"_where": "/home/burchettm/statsbot/node_modules/log4js",
|
||||
"author": {
|
||||
"name": "Gareth Jones",
|
||||
"email": "gareth.nomiddlename@gmail.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/nomiddlename/streamroller/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"date-format": "^0.0.0",
|
||||
"debug": "^0.7.2",
|
||||
"mkdirp": "^0.5.1",
|
||||
"readable-stream": "^1.1.7"
|
||||
},
|
||||
"description": "file streams that roll over when size limits, or dates are reached",
|
||||
"devDependencies": {
|
||||
"async": "^0.2.9",
|
||||
"jshint": "^2.9.4",
|
||||
"mocha": "^1.12.0",
|
||||
"sandboxed-module": "^0.2.1",
|
||||
"should": "^1.2.2"
|
||||
},
|
||||
"directories": {
|
||||
"test": "test"
|
||||
},
|
||||
"dist": {
|
||||
"shasum": "a273f1f91994549a2ddd112ccaa2d1dd23cb758c",
|
||||
"tarball": "https://registry.npmjs.org/streamroller/-/streamroller-0.4.0.tgz"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.12.0"
|
||||
},
|
||||
"gitHead": "ece35d7d86c87c04ff09e8604accae81cf36a0ce",
|
||||
"homepage": "https://github.com/nomiddlename/streamroller#readme",
|
||||
"keywords": [
|
||||
"stream",
|
||||
"rolling"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "csausdev",
|
||||
"email": "gareth.jones@sensis.com.au"
|
||||
}
|
||||
],
|
||||
"name": "streamroller",
|
||||
"optionalDependencies": {},
|
||||
"readme": "ERROR: No README data found!",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/nomiddlename/streamroller.git"
|
||||
},
|
||||
"scripts": {
|
||||
"pretest": "jshint lib/ test/",
|
||||
"test": "mocha"
|
||||
},
|
||||
"version": "0.4.0"
|
||||
}
|
93
node_modules/streamroller/test/BaseRollingFileStream-test.js
generated
vendored
Normal file
93
node_modules/streamroller/test/BaseRollingFileStream-test.js
generated
vendored
Normal file
@ -0,0 +1,93 @@
|
||||
"use strict";
|
||||
var should = require('should')
|
||||
, fs = require('fs')
|
||||
, sandbox = require('sandboxed-module');
|
||||
|
||||
describe('BaseRollingFileStream', function() {
|
||||
describe('when no filename is passed', function() {
|
||||
it('should throw an error', function() {
|
||||
var BaseRollingFileStream = require('../lib/BaseRollingFileStream');
|
||||
(function() {
|
||||
new BaseRollingFileStream();
|
||||
}).should.throw();
|
||||
});
|
||||
});
|
||||
|
||||
describe('default behaviour', function() {
|
||||
var stream;
|
||||
|
||||
before(function() {
|
||||
var BaseRollingFileStream = require('../lib/BaseRollingFileStream');
|
||||
stream = new BaseRollingFileStream('basetest.log');
|
||||
});
|
||||
|
||||
after(function(done) {
|
||||
fs.unlink('basetest.log', done);
|
||||
});
|
||||
|
||||
it('should not want to roll', function() {
|
||||
stream.shouldRoll().should.eql(false);
|
||||
});
|
||||
|
||||
it('should not roll', function() {
|
||||
var cbCalled = false;
|
||||
//just calls the callback straight away, no async calls
|
||||
stream.roll('basetest.log', function() { cbCalled = true; });
|
||||
cbCalled.should.eql(true);
|
||||
});
|
||||
|
||||
it('should pass options to the underlying write stream', function() {
|
||||
var underlyingStreamOptions;
|
||||
|
||||
var BaseRollingFileStream = sandbox.require(
|
||||
'../lib/BaseRollingFileStream',
|
||||
{
|
||||
requires: {
|
||||
'fs': {
|
||||
createWriteStream: function(filename, options) {
|
||||
underlyingStreamOptions = options;
|
||||
return {
|
||||
on: function() {}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
var stream = new BaseRollingFileStream('cheese.log', { encoding: 'utf904'});
|
||||
stream.openTheStream();
|
||||
|
||||
underlyingStreamOptions.should.eql({ encoding: 'utf904', mode: 420, flags: 'a'});
|
||||
});
|
||||
});
|
||||
|
||||
describe('when end is called', function() {
|
||||
it('should close the underlying stream', function(done) {
|
||||
var stream = new (require('../lib/BaseRollingFileStream'))('cheese.log');
|
||||
|
||||
stream.theStream.on('close', function() {
|
||||
done();
|
||||
});
|
||||
|
||||
stream.end();
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the file is in a non-existent directory', function() {
|
||||
var stream;
|
||||
before(function() {
|
||||
var BaseRollingFileStream = require('../lib/BaseRollingFileStream');
|
||||
stream = new BaseRollingFileStream('subdir/test.log');
|
||||
});
|
||||
|
||||
after(function() {
|
||||
fs.unlinkSync('subdir/test.log');
|
||||
fs.rmdir('subdir');
|
||||
});
|
||||
|
||||
it('should create the directory', function() {
|
||||
fs.existsSync('subdir/test.log').should.eql(true);
|
||||
stream.end();
|
||||
});
|
||||
});
|
||||
});
|
508
node_modules/streamroller/test/DateRollingFileStream-test.js
generated
vendored
Normal file
508
node_modules/streamroller/test/DateRollingFileStream-test.js
generated
vendored
Normal file
@ -0,0 +1,508 @@
|
||||
"use strict";
|
||||
var should = require('should')
|
||||
, fs = require('fs')
|
||||
, zlib = require('zlib')
|
||||
, util = require('util')
|
||||
, async = require('async')
|
||||
, format = require('date-format')
|
||||
, streams = require('readable-stream')
|
||||
, DateRollingFileStream
|
||||
, testTime = new Date(2012, 8, 12, 10, 37, 11);
|
||||
|
||||
DateRollingFileStream = require('../lib').DateRollingFileStream;
|
||||
|
||||
function remove(filename, cb) {
|
||||
fs.unlink(filename, function () {
|
||||
cb();
|
||||
});
|
||||
}
|
||||
|
||||
function now() {
|
||||
return testTime.getTime();
|
||||
}
|
||||
|
||||
describe('DateRollingFileStream', function () {
|
||||
describe('arguments', function () {
|
||||
var stream;
|
||||
|
||||
before(function (done) {
|
||||
stream = new DateRollingFileStream(
|
||||
__dirname + '/test-date-rolling-file-stream-1',
|
||||
'yyyy-mm-dd.hh'
|
||||
);
|
||||
done();
|
||||
});
|
||||
|
||||
after(function (done) {
|
||||
remove(__dirname + '/test-date-rolling-file-stream-1', done);
|
||||
});
|
||||
|
||||
it('should take a filename and a pattern and return a WritableStream', function (done) {
|
||||
stream.filename.should.eql(__dirname + '/test-date-rolling-file-stream-1');
|
||||
stream.pattern.should.eql('yyyy-mm-dd.hh');
|
||||
stream.should.be.instanceOf(streams.Writable);
|
||||
done();
|
||||
});
|
||||
|
||||
it('with default settings for the underlying stream', function (done) {
|
||||
stream.theStream.mode.should.eql(420);
|
||||
stream.theStream.flags.should.eql('a');
|
||||
//encoding is not available on the underlying stream
|
||||
//assert.equal(stream.encoding, 'utf8');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('default arguments', function () {
|
||||
var stream;
|
||||
|
||||
before(function(done) {
|
||||
stream = new DateRollingFileStream(__dirname + '/test-date-rolling-file-stream-2');
|
||||
done();
|
||||
});
|
||||
|
||||
after(function (done) {
|
||||
remove(__dirname + '/test-date-rolling-file-stream-2', done);
|
||||
});
|
||||
|
||||
it('should have pattern of .yyyy-MM-dd', function (done) {
|
||||
stream.pattern.should.eql('.yyyy-MM-dd');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('with stream arguments', function () {
|
||||
var stream;
|
||||
|
||||
before(function(done) {
|
||||
stream = new DateRollingFileStream(
|
||||
__dirname + '/test-date-rolling-file-stream-3',
|
||||
'yyyy-MM-dd',
|
||||
{mode: parseInt('0666', 8)}
|
||||
);
|
||||
done();
|
||||
});
|
||||
|
||||
after(function (done) {
|
||||
remove(__dirname + '/test-date-rolling-file-stream-3', done);
|
||||
});
|
||||
|
||||
it('should pass them to the underlying stream', function (done) {
|
||||
stream.theStream.mode.should.eql(parseInt('0666', 8));
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('with stream arguments but no pattern', function () {
|
||||
var stream;
|
||||
|
||||
before(function (done) {
|
||||
stream = new DateRollingFileStream(
|
||||
__dirname + '/test-date-rolling-file-stream-4',
|
||||
{mode: parseInt('0666', 8)}
|
||||
);
|
||||
done();
|
||||
});
|
||||
|
||||
after(function (done) {
|
||||
remove(__dirname + '/test-date-rolling-file-stream-4', done);
|
||||
});
|
||||
|
||||
it('should pass them to the underlying stream', function (done) {
|
||||
stream.theStream.mode.should.eql(parseInt('0666', 8));
|
||||
done();
|
||||
});
|
||||
|
||||
it('should use default pattern', function (done) {
|
||||
stream.pattern.should.eql('.yyyy-MM-dd');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('with a pattern of .yyyy-MM-dd', function () {
|
||||
var stream;
|
||||
|
||||
before(function (done) {
|
||||
stream = new DateRollingFileStream(
|
||||
__dirname + '/test-date-rolling-file-stream-5', '.yyyy-MM-dd',
|
||||
null,
|
||||
now
|
||||
);
|
||||
stream.write("First message\n", 'utf8', done);
|
||||
});
|
||||
|
||||
after(function (done) {
|
||||
remove(__dirname + '/test-date-rolling-file-stream-5', done);
|
||||
});
|
||||
|
||||
it('should create a file with the base name', function (done) {
|
||||
fs.readFile(__dirname + '/test-date-rolling-file-stream-5', 'utf8', function (err, contents) {
|
||||
contents.should.eql("First message\n");
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the day changes', function () {
|
||||
|
||||
before(function (done) {
|
||||
testTime = new Date(2012, 8, 13, 0, 10, 12);
|
||||
stream.write("Second message\n", 'utf8', done);
|
||||
});
|
||||
|
||||
after(function (done) {
|
||||
remove(__dirname + '/test-date-rolling-file-stream-5.2012-09-12', done);
|
||||
});
|
||||
|
||||
describe('the number of files', function () {
|
||||
var files = [];
|
||||
|
||||
before(function (done) {
|
||||
fs.readdir(__dirname, function (err, list) {
|
||||
files = list;
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
it('should be two', function (done) {
|
||||
files.filter(
|
||||
function (file) {
|
||||
return file.indexOf('test-date-rolling-file-stream-5') > -1;
|
||||
}
|
||||
).should.have.length(2);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('the file without a date', function () {
|
||||
it('should contain the second message', function (done) {
|
||||
fs.readFile(
|
||||
__dirname + '/test-date-rolling-file-stream-5', 'utf8',
|
||||
function (err, contents) {
|
||||
contents.should.eql("Second message\n");
|
||||
done(err);
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('the file with the date', function () {
|
||||
it('should contain the first message', function (done) {
|
||||
fs.readFile(
|
||||
__dirname + '/test-date-rolling-file-stream-5.2012-09-12', 'utf8',
|
||||
function (err, contents) {
|
||||
contents.should.eql("First message\n");
|
||||
done(err);
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('with alwaysIncludePattern', function () {
|
||||
var stream;
|
||||
|
||||
before(function (done) {
|
||||
testTime = new Date(2012, 8, 12, 0, 10, 12);
|
||||
remove(
|
||||
__dirname + '/test-date-rolling-file-stream-pattern.2012-09-12',
|
||||
function () {
|
||||
stream = new DateRollingFileStream(
|
||||
__dirname + '/test-date-rolling-file-stream-pattern',
|
||||
'.yyyy-MM-dd',
|
||||
{alwaysIncludePattern: true},
|
||||
now
|
||||
);
|
||||
stream.write("First message\n", 'utf8', done);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
after(function (done) {
|
||||
remove(__dirname + '/test-date-rolling-file-stream-pattern.2012-09-12', done);
|
||||
});
|
||||
|
||||
it('should create a file with the pattern set', function (done) {
|
||||
fs.readFile(
|
||||
__dirname + '/test-date-rolling-file-stream-pattern.2012-09-12', 'utf8',
|
||||
function (err, contents) {
|
||||
contents.should.eql("First message\n");
|
||||
done(err);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
describe('when the day changes', function () {
|
||||
before(function (done) {
|
||||
testTime = new Date(2012, 8, 13, 0, 10, 12);
|
||||
stream.write("Second message\n", 'utf8', done);
|
||||
});
|
||||
|
||||
after(function (done) {
|
||||
remove(__dirname + '/test-date-rolling-file-stream-pattern.2012-09-13', done);
|
||||
});
|
||||
|
||||
describe('the number of files', function () {
|
||||
it('should be two', function (done) {
|
||||
fs.readdir(__dirname, function (err, files) {
|
||||
files.filter(
|
||||
function (file) {
|
||||
return file.indexOf('test-date-rolling-file-stream-pattern') > -1;
|
||||
}
|
||||
).should.have.length(2);
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('the file with the later date', function () {
|
||||
it('should contain the second message', function (done) {
|
||||
fs.readFile(
|
||||
__dirname + '/test-date-rolling-file-stream-pattern.2012-09-13', 'utf8',
|
||||
function (err, contents) {
|
||||
contents.should.eql("Second message\n");
|
||||
done(err);
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('the file with the date', function () {
|
||||
it('should contain the first message', function (done) {
|
||||
fs.readFile(
|
||||
__dirname + '/test-date-rolling-file-stream-pattern.2012-09-12', 'utf8',
|
||||
function (err, contents) {
|
||||
contents.should.eql("First message\n");
|
||||
done(err);
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('with compress option', function () {
|
||||
var stream;
|
||||
|
||||
before(function (done) {
|
||||
testTime = new Date(2012, 8, 12, 0, 10, 12);
|
||||
stream = new DateRollingFileStream(
|
||||
__dirname + '/compressed.log',
|
||||
'.yyyy-MM-dd',
|
||||
{compress: true},
|
||||
now
|
||||
);
|
||||
stream.write("First message\n", 'utf8', done);
|
||||
});
|
||||
|
||||
describe('when the day changes', function () {
|
||||
before(function (done) {
|
||||
testTime = new Date(2012, 8, 13, 0, 10, 12);
|
||||
stream.write("Second message\n", 'utf8', done);
|
||||
});
|
||||
|
||||
it('should be two files, one compressed', function (done) {
|
||||
fs.readdir(__dirname, function (err, files) {
|
||||
var logFiles = files.filter(
|
||||
function (file) {
|
||||
return file.indexOf('compressed.log') > -1;
|
||||
}
|
||||
);
|
||||
logFiles.should.have.length(2);
|
||||
|
||||
zlib.gunzip(
|
||||
fs.readFileSync(__dirname + '/compressed.log.2012-09-12.gz'),
|
||||
function (err, contents) {
|
||||
contents.toString('utf8').should.eql('First message\n');
|
||||
fs.readFileSync(__dirname + '/compressed.log', 'utf8').should.eql('Second message\n');
|
||||
done(err);
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
after(function (done) {
|
||||
remove(
|
||||
__dirname + '/compressed.log',
|
||||
function () {
|
||||
remove(__dirname + '/compressed.log.2012-09-12.gz', done);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('with daysToKeep option', function () {
|
||||
var stream;
|
||||
var daysToKeep = 4;
|
||||
var numOriginalLogs = 10;
|
||||
|
||||
before(function (done) {
|
||||
var day = 0;
|
||||
var streams = [];
|
||||
async.whilst(
|
||||
function () {
|
||||
return day < numOriginalLogs;
|
||||
},
|
||||
function (nextCallback) {
|
||||
testTime = new Date(2012, 8, 20 - day, 0, 10, 12);
|
||||
var currentStream = new DateRollingFileStream(
|
||||
__dirname + '/daysToKeep.log',
|
||||
'.yyyy-MM-dd',
|
||||
{
|
||||
alwaysIncludePattern: true,
|
||||
daysToKeep: daysToKeep
|
||||
},
|
||||
now
|
||||
);
|
||||
async.waterfall([
|
||||
function (callback) {
|
||||
currentStream.write(util.format("Message on day %d\n", day), 'utf8', callback);
|
||||
},
|
||||
function (callback) {
|
||||
fs.utimes(currentStream.filename, testTime, testTime, callback);
|
||||
}
|
||||
],
|
||||
function (err) {
|
||||
day++;
|
||||
streams.push(currentStream);
|
||||
nextCallback(err);
|
||||
});
|
||||
},
|
||||
function (err, n) {
|
||||
stream = streams[0];
|
||||
done(err);
|
||||
});
|
||||
|
||||
describe('when the day changes', function () {
|
||||
before(function (done) {
|
||||
testTime = new Date(2012, 8, 21, 0, 10, 12);
|
||||
stream.write("Second message\n", 'utf8', done);
|
||||
});
|
||||
|
||||
it('should be daysToKeep + 1 files left from numOriginalLogs', function (done) {
|
||||
fs.readdir(__dirname, function (err, files) {
|
||||
var logFiles = files.filter(
|
||||
function (file) {
|
||||
return file.indexOf('daysToKeep.log') > -1;
|
||||
}
|
||||
);
|
||||
logFiles.should.have.length(daysToKeep + 1);
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
after(function (done) {
|
||||
fs.readdir(__dirname, function (err, files) {
|
||||
var logFiles = files.filter(
|
||||
function (file) {
|
||||
return file.indexOf('daysToKeep.log') > -1;
|
||||
}
|
||||
);
|
||||
async.each(logFiles, function (logFile, nextCallback) {
|
||||
remove(__dirname + "/" + logFile, nextCallback);
|
||||
},
|
||||
function (err) {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('with daysToKeep and compress options', function () {
|
||||
var stream;
|
||||
var daysToKeep = 4;
|
||||
var numOriginalLogs = 10;
|
||||
|
||||
before(function (done) {
|
||||
var day = 0;
|
||||
var streams = [];
|
||||
async.whilst(
|
||||
function () {
|
||||
return day < numOriginalLogs;
|
||||
},
|
||||
function (nextCallback) {
|
||||
testTime = new Date(2012, 8, 20 - day, 0, 10, 12);
|
||||
var currentStream = new DateRollingFileStream(
|
||||
__dirname + '/compressedDaysToKeep.log',
|
||||
'.yyyy-MM-dd',
|
||||
{
|
||||
alwaysIncludePattern: true,
|
||||
compress: true,
|
||||
daysToKeep: daysToKeep
|
||||
},
|
||||
now
|
||||
);
|
||||
async.waterfall([
|
||||
function (callback) {
|
||||
currentStream.write(util.format("Message on day %d\n", day), 'utf8', callback);
|
||||
},
|
||||
function (callback) {
|
||||
currentStream.compress(currentStream.filename, callback);
|
||||
},
|
||||
function (callback) {
|
||||
fs.utimes(currentStream.filename + ".gz", testTime, testTime, callback);
|
||||
}
|
||||
],
|
||||
function (err) {
|
||||
day++;
|
||||
streams.push(currentStream);
|
||||
nextCallback(err);
|
||||
});
|
||||
},
|
||||
function (err, n) {
|
||||
|
||||
// Uncompress the most recent stream which will be the one we roll over
|
||||
// for testing
|
||||
stream = streams[0];
|
||||
var compressedFilename = stream.filename + '.gz';
|
||||
var gzip = zlib.createGzip();
|
||||
var inp = fs.createReadStream(compressedFilename);
|
||||
var out = fs.createWriteStream(stream.filename);
|
||||
inp.pipe(gzip).pipe(out);
|
||||
|
||||
out.on('finish', function (err) {
|
||||
fs.unlink(compressedFilename, done);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the day changes', function () {
|
||||
before(function (done) {
|
||||
testTime = new Date(2012, 8, 21, 0, 10, 12);
|
||||
stream.write("New file message\n", 'utf8', done);
|
||||
});
|
||||
|
||||
it('should be 4 files left from original 3', function (done) {
|
||||
fs.readdir(__dirname, function (err, files) {
|
||||
var logFiles = files.filter(
|
||||
function (file) {
|
||||
return file.indexOf('compressedDaysToKeep.log') > -1;
|
||||
}
|
||||
);
|
||||
logFiles.should.have.length(daysToKeep + 1);
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
after(function (done) {
|
||||
fs.readdir(__dirname, function (err, files) {
|
||||
var logFiles = files.filter(
|
||||
function (file) {
|
||||
return file.indexOf('compressedDaysToKeep.log') > -1;
|
||||
}
|
||||
);
|
||||
async.each(logFiles, function (logFile, nextCallback) {
|
||||
remove(__dirname + "/" + logFile, nextCallback);
|
||||
},
|
||||
function (err) {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
357
node_modules/streamroller/test/RollingFileStream-test.js
generated
vendored
Normal file
357
node_modules/streamroller/test/RollingFileStream-test.js
generated
vendored
Normal file
@ -0,0 +1,357 @@
|
||||
"use strict";
|
||||
var async = require('async')
|
||||
, should = require('should')
|
||||
, fs = require('fs')
|
||||
, path = require('path')
|
||||
, zlib = require('zlib')
|
||||
, streams = require('readable-stream')
|
||||
, RollingFileStream = require('../lib').RollingFileStream;
|
||||
|
||||
function remove(filename, cb) {
|
||||
fs.unlink(filename, function(err) { cb(); });
|
||||
}
|
||||
|
||||
function create(filename, cb) {
|
||||
fs.writeFile(filename, "test file", cb);
|
||||
}
|
||||
|
||||
describe('RollingFileStream', function() {
|
||||
|
||||
describe('arguments', function() {
|
||||
var stream;
|
||||
|
||||
before(function(done) {
|
||||
remove(__dirname + "/test-rolling-file-stream", function() {
|
||||
stream = new RollingFileStream(__dirname + "/test-rolling-file-stream", 1024, 5);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
after(function(done) {
|
||||
remove(__dirname + "/test-rolling-file-stream", done);
|
||||
});
|
||||
|
||||
it('should take a filename, file size (bytes), no. backups, return Writable', function() {
|
||||
stream.should.be.an.instanceOf(streams.Writable);
|
||||
stream.filename.should.eql(__dirname + "/test-rolling-file-stream");
|
||||
stream.size.should.eql(1024);
|
||||
stream.backups.should.eql(5);
|
||||
});
|
||||
|
||||
it('should apply default settings to the underlying stream', function() {
|
||||
stream.theStream.mode.should.eql(420);
|
||||
stream.theStream.flags.should.eql('a');
|
||||
//encoding isn't a property on the underlying stream
|
||||
//assert.equal(stream.theStream.encoding, 'utf8');
|
||||
});
|
||||
});
|
||||
|
||||
describe('with stream arguments', function() {
|
||||
it('should pass them to the underlying stream', function() {
|
||||
var stream = new RollingFileStream(
|
||||
__dirname + '/test-rolling-file-stream',
|
||||
1024,
|
||||
5,
|
||||
{ mode: parseInt('0666', 8) }
|
||||
);
|
||||
stream.theStream.mode.should.eql(parseInt('0666', 8));
|
||||
});
|
||||
|
||||
after(function(done) {
|
||||
remove(__dirname + '/test-rolling-file-stream', done);
|
||||
});
|
||||
});
|
||||
|
||||
describe('without size', function() {
|
||||
it('should default to max int size', function() {
|
||||
var stream = new RollingFileStream(__dirname + "/test-rolling-file-stream");
|
||||
stream.size.should.eql(Number.MAX_SAFE_INTEGER);
|
||||
});
|
||||
|
||||
after(function(done) {
|
||||
remove(__dirname + "/test-rolling-file-stream", done);
|
||||
});
|
||||
});
|
||||
|
||||
describe('without number of backups', function() {
|
||||
it('should default to 1 backup', function() {
|
||||
var stream = new RollingFileStream(__dirname + "/test-rolling-file-stream", 1024);
|
||||
stream.backups.should.eql(1);
|
||||
});
|
||||
|
||||
after(function(done) {
|
||||
remove(__dirname + "/test-rolling-file-stream", done);
|
||||
});
|
||||
});
|
||||
|
||||
describe('writing less than the file size', function() {
|
||||
|
||||
before(function(done) {
|
||||
remove(__dirname + "/test-rolling-file-stream-write-less", function() {
|
||||
var stream = new RollingFileStream(
|
||||
__dirname + "/test-rolling-file-stream-write-less",
|
||||
100
|
||||
);
|
||||
stream.write("cheese", "utf8", function() {
|
||||
stream.end(done);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
after(function(done) {
|
||||
remove(__dirname + "/test-rolling-file-stream-write-less", done);
|
||||
});
|
||||
|
||||
it('should write to the file', function(done) {
|
||||
fs.readFile(
|
||||
__dirname + "/test-rolling-file-stream-write-less", "utf8",
|
||||
function(err, contents) {
|
||||
contents.should.eql("cheese");
|
||||
done(err);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should write one file', function(done) {
|
||||
fs.readdir(__dirname, function(err, files) {
|
||||
files.filter(
|
||||
function(file) { return file.indexOf('test-rolling-file-stream-write-less') > -1; }
|
||||
).should.have.length(1);
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('writing more than the file size', function() {
|
||||
before(function(done) {
|
||||
async.forEach(
|
||||
[
|
||||
__dirname + "/test-rolling-file-stream-write-more",
|
||||
__dirname + "/test-rolling-file-stream-write-more.1"
|
||||
],
|
||||
remove,
|
||||
function() {
|
||||
var stream = new RollingFileStream(
|
||||
__dirname + "/test-rolling-file-stream-write-more",
|
||||
45
|
||||
);
|
||||
async.forEachSeries(
|
||||
[0, 1, 2, 3, 4, 5, 6],
|
||||
function(i, cb) {
|
||||
stream.write(i +".cheese\n", "utf8", cb);
|
||||
},
|
||||
function() {
|
||||
stream.end(done);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
after(function(done) {
|
||||
async.forEach(
|
||||
[
|
||||
__dirname + "/test-rolling-file-stream-write-more",
|
||||
__dirname + "/test-rolling-file-stream-write-more.1"
|
||||
],
|
||||
remove,
|
||||
done
|
||||
);
|
||||
});
|
||||
|
||||
it('should write two files' , function(done) {
|
||||
fs.readdir(__dirname, function(err, files) {
|
||||
files.filter(
|
||||
function(file) {
|
||||
return file.indexOf('test-rolling-file-stream-write-more') > -1;
|
||||
}
|
||||
).should.have.length(2);
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
it('should write the last two log messages to the first file', function(done) {
|
||||
fs.readFile(
|
||||
__dirname + "/test-rolling-file-stream-write-more", "utf8",
|
||||
function(err, contents) {
|
||||
contents.should.eql('5.cheese\n6.cheese\n');
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
it('should write the first five log messages to the second file', function(done) {
|
||||
fs.readFile(
|
||||
__dirname + '/test-rolling-file-stream-write-more.1', "utf8",
|
||||
function(err, contents) {
|
||||
contents.should.eql('0.cheese\n1.cheese\n2.cheese\n3.cheese\n4.cheese\n');
|
||||
done(err);
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('with options.compress = true', function() {
|
||||
before(function(done) {
|
||||
var stream = new RollingFileStream(
|
||||
path.join(__dirname, 'compressed-backups.log'),
|
||||
30, //30 bytes max size
|
||||
2, //two backup files to keep
|
||||
{ compress: true }
|
||||
);
|
||||
async.forEachSeries(
|
||||
[
|
||||
"This is the first log message.",
|
||||
"This is the second log message.",
|
||||
"This is the third log message.",
|
||||
"This is the fourth log message."
|
||||
],
|
||||
function(i, cb) {
|
||||
stream.write(i + "\n", "utf8", cb);
|
||||
},
|
||||
function() {
|
||||
stream.end(done);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should produce three files, with the backups compressed', function(done) {
|
||||
fs.readdir(__dirname, function(err, files) {
|
||||
var testFiles = files.filter(
|
||||
function(f) { return f.indexOf('compressed-backups.log') > -1; }
|
||||
).sort();
|
||||
|
||||
testFiles.length.should.eql(3);
|
||||
testFiles.should.eql([
|
||||
'compressed-backups.log',
|
||||
'compressed-backups.log.1.gz',
|
||||
'compressed-backups.log.2.gz',
|
||||
]);
|
||||
|
||||
fs.readFile(path.join(__dirname, testFiles[0]), 'utf8', function(err, contents) {
|
||||
contents.should.eql('This is the fourth log message.\n');
|
||||
|
||||
zlib.gunzip(fs.readFileSync(path.join(__dirname, testFiles[1])),
|
||||
function(err, contents) {
|
||||
contents.toString('utf8').should.eql('This is the third log message.\n');
|
||||
zlib.gunzip(fs.readFileSync(path.join(__dirname, testFiles[2])),
|
||||
function(err, contents) {
|
||||
contents.toString('utf8').should.eql('This is the second log message.\n');
|
||||
done(err);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
after(function(done) {
|
||||
async.forEach([
|
||||
path.join(__dirname, 'compressed-backups.log'),
|
||||
path.join(__dirname, 'compressed-backups.log.1.gz'),
|
||||
path.join(__dirname, 'compressed-backups.log.2.gz'),
|
||||
], remove, done);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('when many files already exist', function() {
|
||||
before(function(done) {
|
||||
async.forEach(
|
||||
[
|
||||
__dirname + '/test-rolling-stream-with-existing-files.11',
|
||||
__dirname + '/test-rolling-stream-with-existing-files.20',
|
||||
__dirname + '/test-rolling-stream-with-existing-files.-1',
|
||||
__dirname + '/test-rolling-stream-with-existing-files.1.1',
|
||||
__dirname + '/test-rolling-stream-with-existing-files.1'
|
||||
],
|
||||
remove,
|
||||
function(err) {
|
||||
if (err) done(err);
|
||||
|
||||
async.forEach(
|
||||
[
|
||||
__dirname + '/test-rolling-stream-with-existing-files.11',
|
||||
__dirname + '/test-rolling-stream-with-existing-files.20',
|
||||
__dirname + '/test-rolling-stream-with-existing-files.-1',
|
||||
__dirname + '/test-rolling-stream-with-existing-files.1.1',
|
||||
__dirname + '/test-rolling-stream-with-existing-files.1'
|
||||
],
|
||||
create,
|
||||
function(err) {
|
||||
if (err) done(err);
|
||||
|
||||
var stream = new RollingFileStream(
|
||||
__dirname + "/test-rolling-stream-with-existing-files",
|
||||
45,
|
||||
5
|
||||
);
|
||||
|
||||
async.forEachSeries(
|
||||
[0, 1, 2, 3, 4, 5, 6],
|
||||
function(i, cb) {
|
||||
stream.write(i +".cheese\n", "utf8", cb);
|
||||
},
|
||||
function() {
|
||||
stream.end(done);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
after(function(done) {
|
||||
async.forEach([
|
||||
__dirname + '/test-rolling-stream-with-existing-files',
|
||||
__dirname + '/test-rolling-stream-with-existing-files.0',
|
||||
__dirname + '/test-rolling-stream-with-existing-files.1',
|
||||
__dirname + '/test-rolling-stream-with-existing-files.2',
|
||||
__dirname + '/test-rolling-stream-with-existing-files.3',
|
||||
__dirname + '/test-rolling-stream-with-existing-files.4',
|
||||
__dirname + '/test-rolling-stream-with-existing-files.5',
|
||||
__dirname + '/test-rolling-stream-with-existing-files.11',
|
||||
__dirname + '/test-rolling-stream-with-existing-files.20'
|
||||
], remove, done);
|
||||
});
|
||||
|
||||
it('should roll the files', function(done) {
|
||||
fs.readdir(__dirname, function(err, files) {
|
||||
files.should.include('test-rolling-stream-with-existing-files');
|
||||
files.should.include('test-rolling-stream-with-existing-files.1');
|
||||
files.should.include('test-rolling-stream-with-existing-files.2');
|
||||
files.should.include('test-rolling-stream-with-existing-files.11');
|
||||
files.should.include('test-rolling-stream-with-existing-files.20');
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the directory gets deleted', function() {
|
||||
var stream;
|
||||
before(function(done) {
|
||||
stream = new RollingFileStream(path.join('subdir', 'test-rolling-file-stream'), 5, 5);
|
||||
stream.write('initial', 'utf8', done);
|
||||
});
|
||||
|
||||
after(function() {
|
||||
fs.unlinkSync(path.join('subdir', 'test-rolling-file-stream'));
|
||||
fs.rmdirSync('subdir');
|
||||
});
|
||||
|
||||
it('handles directory deletion gracefully', function(done) {
|
||||
stream.theStream.on('error', done);
|
||||
|
||||
remove(path.join('subdir', 'test-rolling-file-stream'), function() {
|
||||
fs.rmdir('subdir', function() {
|
||||
stream.write('rollover', 'utf8', function() {
|
||||
fs.readFileSync(path.join('subdir', 'test-rolling-file-stream'), 'utf8')
|
||||
.should.eql('rollover');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
28
node_modules/streamroller/test/read-only-file-test.js
generated
vendored
Normal file
28
node_modules/streamroller/test/read-only-file-test.js
generated
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
"use strict";
|
||||
var should = require('should')
|
||||
, fs = require('fs')
|
||||
, path = require('path')
|
||||
, streamroller = require('../lib/index.js');
|
||||
|
||||
describe('when the destination file is read-only', function() {
|
||||
var testFile = path.join(__dirname, 'read-only-file.log');
|
||||
before(function() {
|
||||
fs.writeFileSync(
|
||||
testFile,
|
||||
"Some test content"
|
||||
);
|
||||
fs.chmodSync(testFile, 292 /* 0o444 - octal literals not allowed in old node */);
|
||||
});
|
||||
|
||||
it('should generate an error when writing', function(done) {
|
||||
var stream = new streamroller.RollingFileStream(testFile);
|
||||
stream.on('error', function(e) {
|
||||
e.code.should.eql('EACCES');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
after(function() {
|
||||
fs.unlinkSync(testFile);
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user