"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/asar-require/lib/require.js" (8 Mar 2017, 3671 Bytes) of archive /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 (function() {
    2   var asar, asarStatsToFsStats, error, fakeTime, fs, gid, module_findPath, nextInode, node_module, path, readFileSync, realpathSync, splitPath, statSync, uid;
    3 
    4   asar = require('asar');
    5 
    6   fs = require('fs');
    7 
    8   path = require('path');
    9 
   10   try {
   11     node_module = require('module');
   12   } catch (_error) {
   13     error = _error;
   14     node_module = null;
   15   }
   16 
   17   splitPath = function(p) {
   18     var index;
   19     if (typeof p !== 'string') {
   20       return [false];
   21     }
   22     if (p.substr(-5) === '.asar') {
   23       return [true, p, ''];
   24     }
   25     index = p.lastIndexOf(".asar" + path.sep);
   26     if (index === -1) {
   27       return [false];
   28     }
   29     return [true, p.substr(0, index + 5), p.substr(index + 6)];
   30   };
   31 
   32   nextInode = 0;
   33 
   34   uid = process.getuid != null ? process.getuid() : 0;
   35 
   36   gid = process.getgid != null ? process.getgid() : 0;
   37 
   38   fakeTime = new Date();
   39 
   40   asarStatsToFsStats = function(stats) {
   41     var isFile;
   42     isFile = !stats.files;
   43     return {
   44       dev: 1,
   45       ino: ++nextInode,
   46       mode: 33188,
   47       nlink: 1,
   48       uid: uid,
   49       gid: gid,
   50       rdev: 0,
   51       atime: stats.atime || fakeTime,
   52       birthtime: stats.birthtime || fakeTime,
   53       mtime: stats.mtime || fakeTime,
   54       ctime: stats.ctime || fakeTime,
   55       size: stats.size,
   56       isFile: function() {
   57         return isFile;
   58       },
   59       isDirectory: function() {
   60         return !isFile;
   61       },
   62       isSymbolicLink: function() {
   63         return false;
   64       },
   65       isBlockDevice: function() {
   66         return false;
   67       },
   68       isCharacterDevice: function() {
   69         return false;
   70       },
   71       isFIFO: function() {
   72         return false;
   73       },
   74       isSocket: function() {
   75         return false;
   76       }
   77     };
   78   };
   79 
   80   readFileSync = fs.readFileSync;
   81 
   82   fs.readFileSync = function(p, options) {
   83     var asarPath, content, filePath, isAsar, _ref;
   84     _ref = splitPath(p), isAsar = _ref[0], asarPath = _ref[1], filePath = _ref[2];
   85     if (!isAsar) {
   86       return readFileSync.apply(this, arguments);
   87     }
   88     if (!options) {
   89       options = {
   90         encoding: null,
   91         flag: 'r'
   92       };
   93     } else if (typeof options === 'string') {
   94       options = {
   95         encoding: options,
   96         flag: 'r'
   97       };
   98     } else if (typeof options !== 'object') {
   99       throw new TypeError('Bad arguments');
  100     }
  101     content = asar.extractFile(asarPath, filePath);
  102     if (options.encoding) {
  103       return content.toString(options.encoding);
  104     } else {
  105       return content;
  106     }
  107   };
  108 
  109   statSync = fs.statSync;
  110 
  111   fs.statSync = function(p) {
  112     var asarPath, filePath, isAsar, _ref;
  113     _ref = splitPath(p), isAsar = _ref[0], asarPath = _ref[1], filePath = _ref[2];
  114     if (!isAsar) {
  115       return statSync.apply(this, arguments);
  116     }
  117     return asarStatsToFsStats(asar.statFile(asarPath, filePath));
  118   };
  119 
  120   realpathSync = fs.realpathSync;
  121 
  122   fs.realpathSync = function(p) {
  123     var asarPath, filePath, isAsar, stat, _ref;
  124     _ref = splitPath(p), isAsar = _ref[0], asarPath = _ref[1], filePath = _ref[2];
  125     if (!isAsar) {
  126       return realpathSync.apply(this, arguments);
  127     }
  128     stat = asar.statFile(asarPath, filePath);
  129     if (stat.link) {
  130       filePath = stat.link;
  131     }
  132     return path.join(realpathSync(asarPath), filePath);
  133   };
  134 
  135   if (node_module && node_module._findPath) {
  136     module_findPath = node_module._findPath;
  137     node_module._findPath = function(request, paths, isMain) {
  138       var asarPath, filePath, isAsar, _ref;
  139       _ref = splitPath(request), isAsar = _ref[0], asarPath = _ref[1], filePath = _ref[2];
  140       if (!isAsar) {
  141         return module_findPath.apply(this, arguments);
  142       }
  143       return request;
  144     };
  145   }
  146 
  147 }).call(this);