mjackson / bufferedstream Goto Github PK
View Code? Open in Web Editor NEWA robust stream implementation for node.js and the browser
A robust stream implementation for node.js and the browser
In the flush function, if the "stream.ended" check passes while the stream is paused, BufferedStream will emit an end and wipe out the internal buffer.
The fix seems simple, don't call the end function if the stream is paused (allowing it to resume and flush first)
if (stream.ended && !stream.paused) {
end(stream);
return;
}
Thanks
I was reading the changes for node 0.10 and it has changed the way process.nextTick works so that it always returns before any IO (although it has a failsafe which allows IO after recursion causes it to hit process.maxTickDepth)
So since bufferedStream is supposed to be triggering flush after IO shouldn't we be using the recommended setImmediate() rather than process.nextTick() ?
Otherwise bufferedStream will put things into a tight loop (where no IO is occuring, until it hits process.maxTickDepth, then it will bail out and do some IO).
See
http://blog.nodejs.org/2013/03/11/node-v0-10-0-stable/ (scroll down to 'faster process.nexttick' section)
Ref to setImmediate doc:
http://nodejs.org/api/timers.html#timers_setimmediate_callback_arg
Here is the code I am referencing:
https://github.com/mjijackson/bufferedstream/blob/master/buffered-stream.js#L153
Hi,
See example code below. I was trying to use this module to create simple proxy. However ssh complained of corruption. When I manually connected to server I see an 'echo' of what I type, which is definitely not expected. Seems like duplex streams (like socket) are not supported with pipe?
var net = require('net');
var BufferedStream = require('bufferedstream');
//recieves the socket of the remote end of the tunnel
function Proxy( remoteSocket, localPort ) {
// this buffer insures no data is lost before we have a local socket
var bufferedRemoteSocket = BufferedStream( remoteSocket )
bufferedRemoteSocket.pause()
var onServerConnected = function( localSocket ) {
console.log( 'local connection' )
//duplex pipe
bufferedRemoteSocket.pipe( localSocket ).pipe( bufferedRemoteSocket )
bufferedRemoteSocket.resume()
}
var server = net.createServer( onServerConnected )
server.listen( localPort, 'localhost' )
console.log( 'listening on 22000' )
}
module.exports.Proxy = Proxy
var onConnected = function() {
//console.log('client connected')
proxy = new Proxy( client, 22000 )
}
var client = net.connect({port: 22}, onConnected )
when piping an empty bufferedstream to the http response stream the 'end' event is never emitted and the request hangs until the socket timeout occurs. piping it to a file stream however does work.
it looks like the empty bufferedstream gets paused through the 'pipe' logic and this prevents the 'end' event being emitted. this seems to be a regression of issue #5.
test case:
var http = require('http'),
BufferedStream = require('bufferedstream');
http.createServer(function (req, res) {
var stream = new BufferedStream();
stream.end('');
stream.pipe(res);
// 'end' is never emitted, request hangs...
}).listen(8080, '127.0.0.1');
I am using this package to create a buffered stream that is then consumed by one of the unzip packages. The unzip package has an 'unpipe' call which fails since there is no implementation of 'unpipe' in bufferedstream. Is there a way to implement our own 'unpipe' method on the client?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.