All files / node-unzipper/lib parseExtraField.js

100% Statements 37/37
90.9% Branches 10/11
100% Functions 1/1
100% Lines 37/37

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 3828x 28x 28x 247x 247x 247x 295x 295x 295x 295x 295x 295x 295x 295x 295x 295x 4x 295x 291x 291x 291x 291x 295x 247x 247x 247x 247x 247x 247x 247x 247x 247x 247x 247x 247x 247x 28x  
var parseBuffer = require('./parseBuffer');
 
module.exports = function(extraField, vars) {
  var extra;
  // Find the ZIP64 header, if present.
  while(!extra && extraField && extraField.length) {
    var candidateExtra = parseBuffer.parse(extraField, [
      ['signature', 2],
      ['partsize', 2],
      ['uncompressedSize', 8],
      ['compressedSize', 8],
      ['offset', 8],
      ['disknum', 8],
    ]);
 
    if(candidateExtra.signature === 0x0001) {
      extra = candidateExtra;
    } else {
      // Advance the buffer to the next part.
      // The total size of this part is the 4 byte header + partsize.
      extraField = extraField.slice(candidateExtra.partsize + 4);
    }
  }
 
  extra = extra || {};
 
  if (vars.compressedSize === 0xffffffff)
    vars.compressedSize = extra.compressedSize;
 
  if (vars.uncompressedSize  === 0xffffffff)
    vars.uncompressedSize= extra.uncompressedSize;
 
  if (vars.offsetToLocalFileHeader === 0xffffffff)
    vars.offsetToLocalFileHeader= extra.offset;
 
  return extra;
};