Skip to content

Instantly share code, notes, and snippets.

@tommedema
Created May 2, 2011 11:16
Show Gist options
  • Save tommedema/951463 to your computer and use it in GitHub Desktop.
Save tommedema/951463 to your computer and use it in GitHub Desktop.
var util = require('util'),
fs = require('fs');
module.exports = function(server, everyone) {
server.get('/streamFriendFile', function(req, res) {
util.debug('CLIENT REQUESTED STREAM FRIEND FILE');
util.debug('request headers: ' + util.inspect(req.headers));
util.debug('request params: ' + util.inspect(req.params));
//set headers
res.writeHead(206, {
"Content-Range" : "bytes 0-4349499/4349499",
"Accept-Ranges" : "bytes",
"Content-Length" : 64 * 1024,
"Content-Type" : "audio/mpeg"
});
//mp3 file stream
var readStream = fs.createReadStream('./song.mp3', {
flags : 'r',
encoding : 'binary',
fd : null,
mode : 666,
bufferSize : 64 * 1024
});
//pipe this to the resource
readStream
.on('end', function() {
util.debug('file end!');
})
.on('error', function(err) {
util.debug('file err: ' + err);
})
.pipe(res);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment