             path:       [@options.preroll.path,@options.preroll.key,key,"?"+query].join("/")
 
         conn = req.connection
-        
+
         console.log "firing preroll request", count
         req = http.get opts, (rres) =>
             console.log "got preroll response ", count
             if rres.statusCode == 200
                 # collect preroll and return it so length can be computed
                 pre_data = new Buffer(0)
-                
+
                 rres.on "data", (chunk) =>
                     buf = new Buffer(pre_data.length + chunk.length)
                     pre_data.copy(buf,0)

                # now set up our file read as a stream
                console.log "creating read stream. #{@listeners} active downloads."
                readStreamOpts = bufferSize: 256*1024
                
                # If this is a range request, only deliver that range of bytes
                if rangeRequest
                    console.log "Sending byte range #{rangeStart}-#{rangeEnd}"
                    readStreamOpts['start'] = rangeStart
                    readStreamOpts['end']   = rangeEnd
                
                console.log "read stream opts are", readStreamOpts
                rstream = fs.createReadStream filename, readStreamOpts
                rstream.pipe res, end:false
                
                rstream.on "end", => 
                    # got to the end of the file.  close our response
                    console.log "(stream end) wrote #{ res.socket?.bytesWritten } bytes. #{@listeners} active downloads."
                    res.end()
            
                req.connection.on "end", =>
                    # connection aborted.  destroy our stream
                    console.log "(connection end) wrote #{ res.socket?.bytesWritten } bytes. #{@listeners} active downloads."
                    rstream?.destroy() if rstream?.readable
                
                req.connection.on "close", => 
                    console.log "(conn close) in close. #{@listeners} active downloads."
                    @listeners--
                
                req.connection.setTimeout 30*1000, =>
                    # handle connection timeout
                    res.end()
                    rstream?.destroy() if rstream?.readable
            
    #----------
    
    loadPreroll: (key,req,cb) ->
        count = @_counter++
        
        # short-circuit if we're missing any options
        console.log "preroller opts is ", @options.preroll
        unless @options.preroll?.server && @options.preroll?.key && @options.preroll?.path
            cb?()
            return true
        
        # -- make a request to the preroll server -- #
        
        console.log "making a preroll request"

        # Pass along any query string to Preroller
        query = qs.stringify(req.query)

_u          = require "underscore"
path        = require 'path'
express     = require 'express'
fs          = require "fs"
ffmpegmeta  = require('fluent-ffmpeg').Metadata
http        = require "http"
Parser      = require "./mp3parser"
qs          = require 'qs'

module.exports = class Core
    DefaultOptions:
