understream
Advanced tools
Comparing version 0.4.10 to 0.5.0
// Generated by CoffeeScript 1.6.3 | ||
var ArrayStream, DevNull, EventEmitter, Readable, Understream, Writable, construct, debug, domain, fs, is_readable, _, | ||
var ArrayStream, DevNull, EventEmitter, PassThrough, Readable, StreamCombiner, Understream, Writable, debug, domain, fs, is_readable, pipe_streams_together, _, _ref, | ||
__slice = [].slice, | ||
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, | ||
@@ -7,3 +8,3 @@ __hasProp = {}.hasOwnProperty, | ||
Writable = require('readable-stream').Writable; | ||
_ref = require('readable-stream'), Writable = _ref.Writable, PassThrough = _ref.PassThrough; | ||
@@ -23,14 +24,45 @@ Readable = require('readable-stream'); | ||
is_readable = function(instance) { | ||
return (instance != null) && _.isObject(instance) && instance instanceof EventEmitter && ((instance != null ? instance.pipe : void 0) != null); | ||
return (instance != null) && _.isObject(instance) && instance instanceof EventEmitter && (instance.pipe != null); | ||
}; | ||
construct = function(constructor, args) { | ||
var F; | ||
F = function() { | ||
return constructor.apply(this, args); | ||
}; | ||
F.prototype = constructor.prototype; | ||
return new F(); | ||
pipe_streams_together = function() { | ||
var i, streams, _i, _ref1, _results; | ||
streams = 1 <= arguments.length ? __slice.call(arguments, 0) : []; | ||
if (streams.length < 2) { | ||
return; | ||
} | ||
_results = []; | ||
for (i = _i = 0, _ref1 = streams.length - 2; 0 <= _ref1 ? _i <= _ref1 : _i >= _ref1; i = 0 <= _ref1 ? ++_i : --_i) { | ||
_results.push(streams[i].pipe(streams[i + 1])); | ||
} | ||
return _results; | ||
}; | ||
StreamCombiner = (function(_super) { | ||
__extends(StreamCombiner, _super); | ||
function StreamCombiner() { | ||
var streams, | ||
_this = this; | ||
streams = 1 <= arguments.length ? __slice.call(arguments, 0) : []; | ||
this.pipe = __bind(this.pipe, this); | ||
StreamCombiner.__super__.constructor.call(this, { | ||
objectMode: true | ||
}); | ||
this.head = streams[0]; | ||
this.tail = streams[streams.length - 1]; | ||
pipe_streams_together.apply(null, streams); | ||
this.on('pipe', function(source) { | ||
return source.unpipe(_this).pipe(_this.head); | ||
}); | ||
} | ||
StreamCombiner.prototype.pipe = function(dest, options) { | ||
return this.tail.pipe(dest, options); | ||
}; | ||
return StreamCombiner; | ||
})(PassThrough); | ||
ArrayStream = (function(_super) { | ||
@@ -77,5 +109,7 @@ __extends(ArrayStream, _super); | ||
Understream = (function() { | ||
function Understream(read_stream) { | ||
this.read_stream = read_stream; | ||
function Understream(head) { | ||
this.pipe = __bind(this.pipe, this); | ||
this.stream = __bind(this.stream, this); | ||
this.duplex = __bind(this.duplex, this); | ||
this.readable = __bind(this.readable, this); | ||
this.run = __bind(this.run, this); | ||
@@ -87,9 +121,9 @@ this.defaults = __bind(this.defaults, this); | ||
}; | ||
if (_(this.read_stream).isArray()) { | ||
this.read_stream = new ArrayStream({}, this.read_stream); | ||
this.read_streams = [this.read_stream]; | ||
} else if (is_readable(this.read_stream)) { | ||
this.read_streams = [this.read_stream]; | ||
} else if (this.read_stream == null) { | ||
this.read_streams = []; | ||
if (_(head).isArray()) { | ||
head = new ArrayStream({}, head); | ||
} | ||
if (is_readable(head)) { | ||
this._streams = [head]; | ||
} else if (head == null) { | ||
this._streams = []; | ||
} else { | ||
@@ -105,3 +139,3 @@ throw new Error('Understream expects a readable stream, an array, or nothing'); | ||
Understream.prototype.run = function(cb) { | ||
var dmn, interval, report, stream, _i, _len, _ref, | ||
var dmn, handler, interval, report, stream, _i, _len, _ref1, | ||
_this = this; | ||
@@ -114,5 +148,5 @@ if (!_(cb).isFunction()) { | ||
str = ''; | ||
_(_this.read_streams).each(function(stream) { | ||
var _ref, _ref1; | ||
return str += "" + stream.constructor.name + "(" + (((_ref = stream._writableState) != null ? _ref.length : void 0) || '') + " " + (((_ref1 = stream._readableState) != null ? _ref1.length : void 0) || '') + ") "; | ||
_(_this._streams).each(function(stream) { | ||
var _ref1, _ref2; | ||
return str += "" + stream.constructor.name + "(" + (((_ref1 = stream._writableState) != null ? _ref1.length : void 0) || '') + " " + (((_ref2 = stream._readableState) != null ? _ref2.length : void 0) || '') + ") "; | ||
}); | ||
@@ -122,34 +156,20 @@ return console.log(str); | ||
interval = setInterval(report, 5000); | ||
if (_(this.read_streams).last()._transform != null) { | ||
this.read_streams.push(new DevNull()); | ||
if (_(this._streams).last()._transform != null) { | ||
this._streams.push(new DevNull()); | ||
} | ||
_(this.read_streams).last().on('finish', function() { | ||
clearInterval(interval); | ||
return cb(); | ||
}); | ||
dmn = domain.create(); | ||
dmn.on('error', function(err) { | ||
handler = function(err) { | ||
clearInterval(interval); | ||
return cb(err); | ||
}); | ||
_ref = this.read_streams; | ||
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
stream = _ref[_i]; | ||
}; | ||
_(this._streams).last().on('finish', handler); | ||
dmn.on('error', handler); | ||
_ref1 = this._streams; | ||
for (_i = 0, _len = _ref1.length; _i < _len; _i++) { | ||
stream = _ref1[_i]; | ||
dmn.add(stream); | ||
} | ||
dmn.run(function() { | ||
var _j, _ref1, _results; | ||
debug('running'); | ||
if (!(_this.read_streams.length > 1)) { | ||
return; | ||
} | ||
return _((function() { | ||
_results = []; | ||
for (var _j = 0, _ref1 = _this.read_streams.length - 2; 0 <= _ref1 ? _j <= _ref1 : _j >= _ref1; 0 <= _ref1 ? _j++ : _j--){ _results.push(_j); } | ||
return _results; | ||
}).apply(this)).each(function(i) { | ||
var _ref1, _ref2; | ||
debug('piping', (_ref1 = _this.read_streams[i]) != null ? _ref1.constructor.name : void 0, '-->', (_ref2 = _this.read_streams[i + 1]) != null ? _ref2.constructor.name : void 0); | ||
return _this.read_streams[i].pipe(_this.read_streams[i + 1]); | ||
}); | ||
return pipe_streams_together.apply(null, _this._streams); | ||
}); | ||
@@ -159,9 +179,27 @@ return this; | ||
Understream.prototype.readable = function() { | ||
pipe_streams_together.apply(null, this._streams); | ||
return this._streams[this._streams.length - 1]; | ||
}; | ||
Understream.prototype.duplex = function() { | ||
return (function(func, args, ctor) { | ||
ctor.prototype = func.prototype; | ||
var child = new ctor, result = func.apply(child, args); | ||
return Object(result) === result ? result : child; | ||
})(StreamCombiner, this._streams, function(){}); | ||
}; | ||
Understream.prototype.stream = function() { | ||
return this.read_stream; | ||
return this.readable(); | ||
}; | ||
Understream.mixin = function(FunctionOrReadableStreamKlass, name, fn) { | ||
Understream.prototype.pipe = function(stream_instance) { | ||
this._streams.push(stream_instance); | ||
return this; | ||
}; | ||
Understream.mixin = function(FunctionOrStreamKlass, name, fn) { | ||
if (name == null) { | ||
name = Readable.name; | ||
name = FunctionOrStreamKlass.name || Readable.name; | ||
} | ||
@@ -173,18 +211,21 @@ if (fn == null) { | ||
var args, instance; | ||
args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; | ||
if (fn) { | ||
instance = FunctionOrReadableStreamKlass.apply(null, arguments); | ||
instance = FunctionOrStreamKlass.apply(null, args); | ||
} else { | ||
args = _(arguments).toArray(); | ||
if (args.length < FunctionOrReadableStreamKlass.length) { | ||
args = [_(this.defaults).clone()].concat(args); | ||
} else if (args.length === FunctionOrReadableStreamKlass.length) { | ||
if (args.length < FunctionOrStreamKlass.length) { | ||
args.unshift(_(this.defaults).clone()); | ||
} else if (args.length === FunctionOrStreamKlass.length) { | ||
_(args[0]).defaults(this.defaults); | ||
} else { | ||
throw new Error("Expected " + FunctionOrReadableStreamKlass.length + " or " + (FunctionOrReadableStreamKlass.length - 1) + " arguments to " + name + ", got " + args.length); | ||
throw new Error("Expected " + FunctionOrStreamKlass.length + " or " + (FunctionOrStreamKlass.length - 1) + " arguments to " + name + ", got " + args.length); | ||
} | ||
instance = construct(FunctionOrReadableStreamKlass, args); | ||
instance = (function(func, args, ctor) { | ||
ctor.prototype = func.prototype; | ||
var child = new ctor, result = func.apply(child, args); | ||
return Object(result) === result ? result : child; | ||
})(FunctionOrStreamKlass, args, function(){}); | ||
} | ||
this.read_stream = instance; | ||
this.read_streams.push(this.read_stream); | ||
debug('created', this.read_stream.constructor.name, this.read_streams.length); | ||
this.pipe(instance); | ||
debug('created', instance.constructor.name, this._streams.length); | ||
return this; | ||
@@ -200,7 +241,6 @@ }; | ||
return _(fs.readdirSync(dir)).each(function(filename) { | ||
var match; | ||
match = filename.match(new RegExp("^([^\.]\\S+)\\.js$")); | ||
if (match) { | ||
return require("" + dir + "/" + filename)(Understream); | ||
if (!new RegExp("^([^\\.]\\S+)\\.js$").test(filename)) { | ||
return; | ||
} | ||
return require("" + dir + "/" + filename)(Understream); | ||
}); | ||
@@ -212,4 +252,4 @@ }); | ||
return { | ||
stream: function(read_stream) { | ||
return new Understream(read_stream); | ||
stream: function(head) { | ||
return new Understream(head); | ||
} | ||
@@ -216,0 +256,0 @@ }; |
{ | ||
"name": "understream", | ||
"version": "0.4.10", | ||
"version": "0.5.0", | ||
"description": "stream helpers", | ||
@@ -5,0 +5,0 @@ "engines": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
89392
70
996