Created
November 20, 2013 07:16
-
-
Save westonplatter/7559003 to your computer and use it in GitHub Desktop.
stream MP3 through SailsJS framework
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
/** | |
* 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