Skip to content

Instantly share code, notes, and snippets.

@westonplatter
Created November 20, 2013 07:16
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save westonplatter/7559003 to your computer and use it in GitHub Desktop.
Save westonplatter/7559003 to your computer and use it in GitHub Desktop.
stream MP3 through SailsJS framework
/**
* HomeController
*
* @module :: Controller
* @description :: Contains logic for handling requests.
*/
module.exports = {
index: function (req,res) {
var fs = require('fs');
var fullFilePath = '/Users/weston/visible/test.mp3';
var stat = fs.statSync(fullFilePath);
res.writeHead(200, {
'Content-Type': 'audio/mpeg',
'Content-Length': stat.size
});
var readStream = fs.createReadStream(fullFilePath);
readStream.pipe(res);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment