0.0.0 • Published 11 years ago

file-stream v0.0.0

Weekly downloads
5
License
-
Repository
github
Last release
11 years ago

file-stream

file-stream is a little HTTP server helper that streams binary resources. These resources will commonly be audio or video, but any type of file is fair game.

Build status

Install

npm install file-stream

API

file-stream(
 
  path (string):
    the filesystem path of the file being requested.

  request (IncomingMessage):
    the request object provided by http.createServer.

  response (ServerResponse):
    the response object provided by http.createServer.

)

=> handled (boolean)

Example

var http = require('http')
var stream = require('file-stream')
var filepath = '/path/to/file'

http.createServer(function(req, res) {

  // If file-stream can’t handle the request 
  // it will return false.
  if (!stream(filepath, req, res)) {
    res.statusCode = 500
    res.setHeader('Content-Type', 'text/plain')
    res.end('unable to stream ' + filepath + '\n')
  }

}).listen(8080)

License

MIT