404

[ Avaa Bypassed ]




Upload:

Command:

botdev@3.146.176.29: ~ $
/**
 * Module dependencies.
 */

var fs = require('fs');
var uri2path = require('file-uri-to-path');
var NotFoundError = require('./notfound');
var NotModifiedError = require('./notmodified');
var debug = require('debug')('get-uri:file');

/**
 * Module exports.
 */

module.exports = get;

/**
 * Returns a `fs.ReadStream` instance from a "file:" URI.
 *
 * @api protected
 */

function get (parsed, opts, fn) {

  var fd;
  var cache = opts.cache;

  // same as in fs.ReadStream's constructor
  var flags = opts.hasOwnProperty('flags') ? options.flags : 'r';
  var mode = opts.hasOwnProperty('mode') ? options.mode : 438; /*=0666*/

  // convert URI → Path
  var uri = parsed.href;
  var filepath = uri2path(uri);
  debug('normalized pathname: %o', filepath);

  // open() first to get a fd and ensure that the file exists
  fs.open(filepath, flags, mode, onopen);

  function onerror (err) {
    if ('number' == typeof fd) {
      fs.close(fd, onclose);
    }
    fn(err);
  }

  function onclose () {
    debug('closed fd %o', fd);
  }

  function onopen (err, _fd) {
    if (err) {
      if ('ENOENT' == err.code) {
        err = new NotFoundError();
      }
      return onerror(err);
    }
    fd = _fd;

    // now fstat() to check the `mtime` and store the stat object for the cache
    fs.fstat(fd, onstat);
  }

  function onstat (err, stat) {
    if (err) return onerror(err);

    // if a `cache` was provided, check if the file has not been modified
    if (cache && cache.stat && stat && isNotModified(cache.stat, stat)) {
      return onerror(new NotModifiedError());
    }

    // `fs.ReadStream` takes care of calling `fs.close()` on the
    // fd after it's done reading
    opts.fd = fd;
    var rs = fs.createReadStream(null, opts);
    rs.stat = stat;

    fn(null, rs);
  }

  // returns `true` if the `mtime` of the 2 stat objects are equal
  function isNotModified (prev, curr) {
    return +prev.mtime == +curr.mtime;
  }
}

Filemanager

Name Type Size Permission Actions
.github Folder 0755
node_modules Folder 0755
test Folder 0755
History.md File 3.58 KB 0644
README.md File 5.42 KB 0644
data.js File 1.38 KB 0644
file.js File 1.91 KB 0644
ftp.js File 3.1 KB 0644
http.js File 6.38 KB 0644
https.js File 310 B 0644
index.js File 1.83 KB 0644
notfound.js File 565 B 0644
notmodified.js File 598 B 0644
package.json File 3.7 KB 0644