bufferstream
Advanced tools
Comparing version 0.5.0-pre2 to 0.5.0
(function() { | ||
var BufferStream, cli, express, fs, path, spawn; | ||
var __slice = Array.prototype.slice; | ||
@@ -39,3 +38,3 @@ fs = require('fs'); | ||
server.get('/', function(req, res) { | ||
var buffer, file, info, length, oldpipe, _ref; | ||
var buffer, file, length; | ||
_this.ok("start streaming …"); | ||
@@ -45,4 +44,4 @@ res.header('Content-Length', stats.size); | ||
buffer = new BufferStream({ | ||
encoding: 'binary', | ||
size: 'flexible' | ||
size: 'flexible', | ||
blocking: false | ||
}); | ||
@@ -52,3 +51,3 @@ file = spawn('cat', [filename]); | ||
setTimeout(function() { | ||
_this.info("set buffer size to none"); | ||
_this.info("set buffer size to none (buffer.length=" + (buffer != null ? buffer.length : void 0) + ")"); | ||
return buffer != null ? buffer.setSize('none') : void 0; | ||
@@ -60,54 +59,8 @@ }, 500); | ||
}); | ||
_ref = [buffer.pipe, _this.info], oldpipe = _ref[0], info = _ref[1]; | ||
buffer.pipe = function() { | ||
var args; | ||
args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; | ||
info("buffer got new sink."); | ||
return oldpipe.apply(this, args); | ||
}; | ||
buffer.on('pipe', function() { | ||
return _this.info("buffer got new source."); | ||
}); | ||
buffer.on('pause', function() { | ||
return _this.debug("buffer paused."); | ||
}); | ||
buffer.on('resume', function() { | ||
return _this.debug("buffer resumed."); | ||
}); | ||
buffer.on('end', function() { | ||
return _this.info("buffer ended."); | ||
}); | ||
buffer.on('drain', function() { | ||
return _this.debug("buffer drains."); | ||
}); | ||
buffer.on('error', function(err) { | ||
return _this.error("buffer errored: " + err); | ||
}); | ||
res.on('pause', function() { | ||
return _this.debug("res paused."); | ||
}); | ||
res.on('resume', function() { | ||
return _this.debug("res resumed."); | ||
}); | ||
res.on('drain', function() { | ||
return _this.debug("res drains."); | ||
}); | ||
res.on('end', function() { | ||
return _this.info("res ended."); | ||
}); | ||
res.on('error', function(err) { | ||
return _this.error("res errored: " + err); | ||
}); | ||
file.stdout.on('pause', function() { | ||
return _this.debug("file.stdout paused."); | ||
}); | ||
file.stdout.on('resume', function() { | ||
return _this.debug("file.stdout resumed."); | ||
}); | ||
file.stdout.on('drain', function() { | ||
return _this.debug("file.stdout drains."); | ||
}); | ||
file.stdout.on('end', function() { | ||
return _this.debug("file.stdout ended."); | ||
}); | ||
file.on('exit', function(code) { | ||
@@ -114,0 +67,0 @@ return _this.debug("file.stdout exited with code " + code + "."); |
(function() { | ||
var BufferStream, Valve, fn, isArray, isBuffer, split, _ref; | ||
var BufferStream, Stream, fn, isArray, isBuffer, split, _ref; | ||
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; }, __slice = Array.prototype.slice; | ||
Valve = require('valvestream'); | ||
Stream = require('stream').Stream; | ||
@@ -45,6 +45,6 @@ fn = require('./fn'); | ||
__extends(BufferStream, Valve); | ||
__extends(BufferStream, Stream); | ||
function BufferStream(opts) { | ||
var _ref2; | ||
var _ref2, _ref3, _ref4; | ||
var _this = this; | ||
@@ -59,2 +59,3 @@ if (opts == null) opts = {}; | ||
this.setSize = __bind(this.setSize, this); | ||
this.setEncoding = __bind(this.setEncoding, this); | ||
this.toString = __bind(this.toString, this); | ||
@@ -68,3 +69,6 @@ this.getBuffer = __bind(this.getBuffer, this); | ||
if ((_ref2 = opts.size) == null) opts.size = 'none'; | ||
if ((_ref3 = opts.encoding) == null) opts.encoding = null; | ||
if ((_ref4 = opts.blocking) == null) opts.blocking = true; | ||
this.size = opts.size; | ||
this.blocking = opts.blocking; | ||
this.splitters = []; | ||
@@ -74,7 +78,10 @@ this.__defineGetter__('length', function() { | ||
}); | ||
this.setEncoding(opts.encoding); | ||
this.enabled = true; | ||
this.writable = false; | ||
if (this.size === 'flexible') this.writable = true; | ||
this.writable = true; | ||
this.readable = true; | ||
this.finished = false; | ||
this.paused = false; | ||
this.reset(); | ||
BufferStream.__super__.constructor.call(this, opts); | ||
BufferStream.__super__.constructor.call(this); | ||
if (opts.split != null) { | ||
@@ -97,5 +104,10 @@ if (isArray(opts.split)) { | ||
BufferStream.prototype.toString = function() { | ||
return this.buffer.toString(); | ||
var _ref2; | ||
return (_ref2 = this.buffer).toString.apply(_ref2, arguments); | ||
}; | ||
BufferStream.prototype.setEncoding = function(encoding) { | ||
this.encoding = encoding; | ||
}; | ||
BufferStream.prototype.setSize = function(size) { | ||
@@ -143,2 +155,3 @@ this.size = size; | ||
BufferStream.prototype.write = function(buffer, encoding) { | ||
var _this = this; | ||
if (!this.writable) { | ||
@@ -158,13 +171,17 @@ this.emit('error', new Error("Stream is not writable.")); | ||
} | ||
if (this.size === 'flexible') { | ||
if (this.enabled) { | ||
split.call(this); | ||
if (this.finished) return this.clear(); | ||
if (this.paused) return false; | ||
if (this.size === 'none') { | ||
if (this.enabled) split.call(this); | ||
return this.clear(); | ||
} else if (this.size === 'flexible') { | ||
if (this.enabled) split.call(this); | ||
if (this.finished) return this.clear(); | ||
if (this.blocking) { | ||
return true; | ||
} else { | ||
return this.clear(); | ||
process.nextTick(function() { | ||
return _this.emit('drain'); | ||
}); | ||
return false; | ||
} | ||
} else if (this.size === 'none') { | ||
if (this.enabled) this.buffer = split.call(this); | ||
return this.clear(); | ||
} else { | ||
@@ -177,6 +194,7 @@ throw new Error("not implemented yet :("); | ||
var buffer; | ||
if (!this.buffer.length) return; | ||
if (!this.buffer.length) return true; | ||
buffer = this.buffer; | ||
this.reset(); | ||
return this.flush(buffer); | ||
this.emit('data', buffer); | ||
return !this.paused; | ||
}; | ||
@@ -192,17 +210,15 @@ | ||
BufferStream.prototype.pause = function() { | ||
if (this.paused) return; | ||
this.paused = true; | ||
return this.emit('pause'); | ||
}; | ||
BufferStream.prototype.resume = function() { | ||
var source, _i, _len, _ref2; | ||
if (!this.paused || this.jammed === 0) return; | ||
this.jammed--; | ||
if (this.jammed !== 0) return; | ||
if (!this.paused) return; | ||
if (!this.enabled || this.size === 'none' || this.finished) { | ||
this.paused = false; | ||
if (!this.clear()) return; | ||
} | ||
this.emit('drain'); | ||
this.paused = false; | ||
if (!this.enabled || this.size === 'none' || this.finished) this.clear(); | ||
_ref2 = this.sources; | ||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) { | ||
source = _ref2[_i]; | ||
if (source.readable) { | ||
if (typeof source.resume === "function") source.resume(); | ||
} | ||
} | ||
if (this.size === 'none') this.emit('resume'); | ||
@@ -215,2 +231,13 @@ if (this.finished) { | ||
BufferStream.prototype.end = function(data, encoding) { | ||
if (this.finished) return; | ||
this.finished = true; | ||
if (data != null) this.write(data, encoding); | ||
this.writable = false; | ||
if (!this.paused) { | ||
this.emit('end'); | ||
return this.emit('close'); | ||
} | ||
}; | ||
return BufferStream; | ||
@@ -217,0 +244,0 @@ |
{ "name": "bufferstream" | ||
, "description": "painless stream buffering and cutting" | ||
, "version": "0.5.0-pre2" | ||
, "version": "0.5.0" | ||
, "homepage": "https://github.com/dodo/node-bufferstream" | ||
@@ -14,4 +14,3 @@ , "author": "dodo (https://github.com/dodo)" | ||
, "dependencies": { | ||
"buffertools": ">= 1.0.3", | ||
"valvestream": ">= 0.0.1"} | ||
"buffertools": ">= 1.0.3"} | ||
, "devDependencies": { | ||
@@ -18,0 +17,0 @@ "nodeunit": ">= 0.5.4", |
@@ -18,3 +18,2 @@ (function() { | ||
}); | ||
æ.equal(buffer.encoding, 'utf8'); | ||
æ.equal(buffer.length, 0); | ||
@@ -21,0 +20,0 @@ results = ["123", "bufferstream", "a", "bc", "def"]; |
@@ -17,3 +17,3 @@ (function() { | ||
æ.equal(buffer.finished, false); | ||
æ.equal(buffer.writable, false); | ||
æ.equal(buffer.writable, true); | ||
æ.equal(buffer.readable, true); | ||
@@ -20,0 +20,0 @@ æ.equal(buffer.size, 'none'); |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
27360
1
14
607
4
3
- Removedvalvestream@>= 0.0.1
- Removedvalvestream@0.0.1(transitive)