-
-
Save scan/a33925d9a98dc7019584 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
var http = require('http'), | |
fileSystem = require('fs'), | |
path = require('path') | |
util = require('util'); | |
http.createServer(function(request, response) { | |
var filePath = 'path_to_file.mp3'; | |
var stat = fileSystem.statSync(filePath); | |
response.writeHead(200, { | |
'Content-Type': 'audio/mpeg', | |
'Content-Length': stat.size | |
}); | |
var readStream = fileSystem.createReadStream(filePath); | |
// We replaced all the event handlers with a simple call to util.pump() | |
util.pump(readStream, response); | |
}) | |
.listen(2000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment