Skip to content Skip to sidebar Skip to footer

Detecting Successful Read Stream Open

I'm implementing cache for static serving middleware for Express.js, which works as follows — when request comes, middleware first tries to serve file from filesystem, and if the

Solution 1:

Method createReadStream returns a ReadableStream which also an event open. You can add an event handler for the open event so you will know when the resource is valid before piping:

stream.on('open', function() {
    console.log('hit ' + req.url);
    stream.pipe(res);
});

Post a Comment for "Detecting Successful Read Stream Open"