TarFile.read constructor

TarFile.read(
  1. InputStreamBase input,
  2. {bool storeData: true}
)

Implementation

TarFile.read(InputStreamBase input, {bool storeData = true}) {
  final header = input.readBytes(512);

  // The name, linkname, magic, uname, and gname are null-terminated
  // character strings. All other fields are zero-filled octal numbers in
  // ASCII. Each numeric field of width w contains w minus 1 digits, and a
  // null.
  filename = _parseString(header, 100);
  mode = _parseInt(header, 8);
  ownerId = _parseInt(header, 8);
  groupId = _parseInt(header, 8);
  fileSize = _parseInt(header, 12);
  lastModTime = _parseInt(header, 12);
  checksum = _parseInt(header, 8);
  typeFlag = _parseString(header, 1);
  nameOfLinkedFile = _parseString(header, 100);

  ustarIndicator = _parseString(header, 6);
  if (ustarIndicator == 'ustar') {
    ustarVersion = _parseString(header, 2);
    ownerUserName = _parseString(header, 32);
    ownerGroupName = _parseString(header, 32);
    deviceMajorNumber = _parseInt(header, 8);
    deviceMinorNumber = _parseInt(header, 8);
  }

  if (storeData || filename == '././@LongLink') {
    _rawContent = input.readBytes(fileSize);
  } else {
    input.skip(fileSize);
  }

  if (isFile && fileSize > 0) {
    final remainder = fileSize % 512;
    var skiplen = 0;
    if (remainder != 0) {
      skiplen = 512 - remainder;
      input.skip(skiplen);
    }
  }
}