"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/tar/tar.js" (8 Mar 2017, 4116 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 // field paths that every tar file must have.
    2 // header is padded to 512 bytes.
    3 var f = 0
    4   , fields = {}
    5   , path = fields.path = f++
    6   , mode = fields.mode = f++
    7   , uid = fields.uid = f++
    8   , gid = fields.gid = f++
    9   , size = fields.size = f++
   10   , mtime = fields.mtime = f++
   11   , cksum = fields.cksum = f++
   12   , type = fields.type = f++
   13   , linkpath = fields.linkpath = f++
   14   , headerSize = 512
   15   , blockSize = 512
   16   , fieldSize = []
   17 
   18 fieldSize[path] = 100
   19 fieldSize[mode] = 8
   20 fieldSize[uid] = 8
   21 fieldSize[gid] = 8
   22 fieldSize[size] = 12
   23 fieldSize[mtime] = 12
   24 fieldSize[cksum] = 8
   25 fieldSize[type] = 1
   26 fieldSize[linkpath] = 100
   27 
   28 // "ustar\0" may introduce another bunch of headers.
   29 // these are optional, and will be nulled out if not present.
   30 
   31 var ustar = fields.ustar = f++
   32   , ustarver = fields.ustarver = f++
   33   , uname = fields.uname = f++
   34   , gname = fields.gname = f++
   35   , devmaj = fields.devmaj = f++
   36   , devmin = fields.devmin = f++
   37   , prefix = fields.prefix = f++
   38   , fill = fields.fill = f++
   39 
   40 // terminate fields.
   41 fields[f] = null
   42 
   43 fieldSize[ustar] = 6
   44 fieldSize[ustarver] = 2
   45 fieldSize[uname] = 32
   46 fieldSize[gname] = 32
   47 fieldSize[devmaj] = 8
   48 fieldSize[devmin] = 8
   49 fieldSize[prefix] = 155
   50 fieldSize[fill] = 12
   51 
   52 // nb: prefix field may in fact be 130 bytes of prefix,
   53 // a null char, 12 bytes for atime, 12 bytes for ctime.
   54 //
   55 // To recognize this format:
   56 // 1. prefix[130] === ' ' or '\0'
   57 // 2. atime and ctime are octal numeric values
   58 // 3. atime and ctime have ' ' in their last byte
   59 
   60 var fieldEnds = {}
   61   , fieldOffs = {}
   62   , fe = 0
   63 for (var i = 0; i < f; i ++) {
   64   fieldOffs[i] = fe
   65   fieldEnds[i] = (fe += fieldSize[i])
   66 }
   67 
   68 // build a translation table of field paths.
   69 Object.keys(fields).forEach(function (f) {
   70   if (fields[f] !== null) fields[fields[f]] = f
   71 })
   72 
   73 // different values of the 'type' field
   74 // paths match the values of Stats.isX() functions, where appropriate
   75 var types =
   76   { 0: "File"
   77   , "\0": "OldFile" // like 0
   78   , "": "OldFile"
   79   , 1: "Link"
   80   , 2: "SymbolicLink"
   81   , 3: "CharacterDevice"
   82   , 4: "BlockDevice"
   83   , 5: "Directory"
   84   , 6: "FIFO"
   85   , 7: "ContiguousFile" // like 0
   86   // posix headers
   87   , g: "GlobalExtendedHeader" // k=v for the rest of the archive
   88   , x: "ExtendedHeader" // k=v for the next file
   89   // vendor-specific stuff
   90   , A: "SolarisACL" // skip
   91   , D: "GNUDumpDir" // like 5, but with data, which should be skipped
   92   , I: "Inode" // metadata only, skip
   93   , K: "NextFileHasLongLinkpath" // data = link path of next file
   94   , L: "NextFileHasLongPath" // data = path of next file
   95   , M: "ContinuationFile" // skip
   96   , N: "OldGnuLongPath" // like L
   97   , S: "SparseFile" // skip
   98   , V: "TapeVolumeHeader" // skip
   99   , X: "OldExtendedHeader" // like x
  100   }
  101 
  102 Object.keys(types).forEach(function (t) {
  103   types[types[t]] = types[types[t]] || t
  104 })
  105 
  106 // values for the mode field
  107 var modes =
  108   { suid: 04000 // set uid on extraction
  109   , sgid: 02000 // set gid on extraction
  110   , svtx: 01000 // set restricted deletion flag on dirs on extraction
  111   , uread:  0400
  112   , uwrite: 0200
  113   , uexec:  0100
  114   , gread:  040
  115   , gwrite: 020
  116   , gexec:  010
  117   , oread:  4
  118   , owrite: 2
  119   , oexec:  1
  120   , all: 07777
  121   }
  122 
  123 var numeric =
  124   { mode: true
  125   , uid: true
  126   , gid: true
  127   , size: true
  128   , mtime: true
  129   , devmaj: true
  130   , devmin: true
  131   , cksum: true
  132   , atime: true
  133   , ctime: true
  134   , dev: true
  135   , ino: true
  136   , nlink: true
  137   }
  138 
  139 Object.keys(modes).forEach(function (t) {
  140   modes[modes[t]] = modes[modes[t]] || t
  141 })
  142 
  143 var knownExtended =
  144   { atime: true
  145   , charset: true
  146   , comment: true
  147   , ctime: true
  148   , gid: true
  149   , gname: true
  150   , linkpath: true
  151   , mtime: true
  152   , path: true
  153   , realtime: true
  154   , security: true
  155   , size: true
  156   , uid: true
  157   , uname: true }
  158 
  159 
  160 exports.fields = fields
  161 exports.fieldSize = fieldSize
  162 exports.fieldOffs = fieldOffs
  163 exports.fieldEnds = fieldEnds
  164 exports.types = types
  165 exports.modes = modes
  166 exports.numeric = numeric
  167 exports.headerSize = headerSize
  168 exports.blockSize = blockSize
  169 exports.knownExtended = knownExtended
  170 
  171 exports.Pack = require("./lib/pack.js")
  172 exports.Parse = require("./lib/parse.js")
  173 exports.Extract = require("./lib/extract.js")