Skip to content

Instantly share code, notes, and snippets.

@heapwolf
Created August 7, 2012 05:57
Show Gist options
  • Save heapwolf/3282141 to your computer and use it in GitHub Desktop.
Save heapwolf/3282141 to your computer and use it in GitHub Desktop.
http/media-stream
var fs = require('fs');
require('http').createServer(function(req, res) {
if (req.url === '/') {
res.writeHead(200, {'Content-Type': 'video/x-m4v'});
var rs = fs.createReadStream(__dirname + '/video.m4v');
rs.pipe(res);
rs.on('data', function(d) {
console.log('sent', d.length, 'bytes')
});
rs.on('end', function() {
console.log('read stream ended.');
});
} else {
res.writeHead(404);
}
}).listen(4000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment