Created
November 23, 2013 17:25
-
-
Save westonplatter/7617441 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
| // meteor file streaming with iron-router | |
| Router.map(function () { | |
| this.route('home', { | |
| path: '/', | |
| template: 'home', | |
| action: function(){ | |
| console.log("home router fired"); | |
| } | |
| }); | |
| this.route('download', { | |
| path: '/download', | |
| where: 'server', | |
| action: function(){ | |
| var fs = Npm.require("fs"); | |
| var fullFilePath = '/Users/weston/visible/test.mp3'; | |
| var stat = fs.statSync(fullFilePath); | |
| // console.log(stat.size); | |
| this.response.writeHead(200, { | |
| 'Content-Type': 'audio/mpeg', | |
| 'Content-Length': stat.size | |
| }); | |
| var readStream = fs.createReadStream(fullFilePath); | |
| return readStream.pipe(this.response); | |
| } | |
| }); | |
| }); | |
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
| // adjusted from dtrce's example, https://gist.github.com/dtrce/1204243 | |
| // | |
| // nodejs file streaming | |
| // | |
| var http = require('http'), | |
| fileSystem = require('fs'), | |
| path = require('path'); | |
| http.createServer(function(request, response) { | |
| var filePath = 'Users/weston/visible/test.mp3'; | |
| var stat = fileSystem.statSync(filePath); | |
| response.writeHead(200, { | |
| 'Content-Type': 'audio/mpeg', | |
| 'Content-Length': stat.size | |
| }); | |
| var readStream = fileSystem.createReadStream(filePath); | |
| readStream.pipe(response); | |
| }) | |
| .listen(2000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just wondering if you ever got this working?