Send file at `path` with the
given `options` to the iopa context.

@param {Context} iopa context
@param {String} path
@param {Object} [opts]
@return {Function}
@api public
function iopaStaticSend(context, path, opts) {
    opts = opts || {};
    
    return new Promise(function iopaStaticLoad(resolve, reject){
                       var root = opts.root ? normalize(pathResolve(opts.root)) : '';
                       var index = opts.index;
                       var maxage = opts.maxage || 0;
                       var hidden = opts.hidden || false;
                       var sync = opts.sync || false;
                       opts = null;
                       
                       
                       // normalize path
                       path = decode(path);
                       if (path =="")
                         path = "/";
                         
                          var trailingSlash = '/' == path[path.length - 1];
                    
                       if (-1 == path) return reject('failed to decode');
                       
                       // null byte(s)
                       if (~path.indexOf('\0')) return reject('null bytes');
                       
                       // index file support
                       if (index && trailingSlash) path += index;
                       
                       // malicious path
                       if (!root && !isAbsolute(path)) return reject('relative paths require the .root option');
                       if (!root && ~path.indexOf('..')) return reject('malicious path');
                       
                       // relative to root
                       path = normalize(join(root, path));
                       
                       // out of bounds
                       if (root && 0 != path.indexOf(root)) return reject('malicious path');
                       
                       // hidden file support, ignore
                       if (!hidden && leadingDot(path)) return resolve();
                       var stats;
                       try
                       {
                       stats = fs.statSync(path);
                       }
                       catch (err) {
                       return resolve(null);
                       }
                       
                       if (stats.isDirectory())
                       {
                       return resolve(null);
                       }
                       var contentType =  mime.lookup(path) || 'application/octet-stream';
                       
                       context.response.writeHead(200, {
                                               'Content-Type' : contentType,
                                               'Last-Modified' : stats.mtime.toUTCString(),
                                               'Content-Length': stats.size + '',
                                               'Cache-Control': 'max-age=' + (maxage / 1000 | 0)});
                       
                       if (sync)
                       {
                       var bodyBuffer = fs.readFileSync(path);
                       context.response.end(bodyBuffer);
                       bodyBuffer = null;
                       context = null;
                       return resolve();
                       }
                       else
                       {
                       
                       var stream = fs.createReadStream(path, { flags: 'r',
                                                        encoding: null,
                                                        autoClose: true
                                                        });
                       
                       stream.on('error', function(err){
                                 console.log(err);
                                 stream = null;
                                 context = null;
                                 
                                 reject(err);
                                 
                                 });
                       
                       stream.on('end', function(){
                                 context.response.end();
                                 stream = null;
                                 context = null;
                                 resolve();
                            
                                 });
                       
                       stream.pipe(context.response[IOPA.Body]);
                       
                       return;
                       }
                       });
}