Skip to content

Instantly share code, notes, and snippets.

@westonplatter
Created November 23, 2013 17:25
Show Gist options
  • Select an option

  • Save westonplatter/7617441 to your computer and use it in GitHub Desktop.

Select an option

Save westonplatter/7617441 to your computer and use it in GitHub Desktop.
// 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);
}
});
});
// 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);
@SeanBannister
Copy link

Just wondering if you ever got this working?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment