Created
May 2, 2011 11:16
-
-
Save tommedema/951463 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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