ZipFile constructor Null safety

ZipFile(
  1. [InputStreamBase? input,
  2. ZipFileHeader? header,
  3. String? password]
)

Implementation

ZipFile([InputStreamBase? input, this.header, String? password]) {
  if (input != null) {
    signature = input.readUint32();
    if (signature != SIGNATURE) {
      throw ArchiveException('Invalid Zip Signature');
    }

    version = input.readUint16();
    flags = input.readUint16();
    compressionMethod = input.readUint16();
    lastModFileTime = input.readUint16();
    lastModFileDate = input.readUint16();
    crc32 = input.readUint32();
    compressedSize = input.readUint32();
    uncompressedSize = input.readUint32();
    final fnLen = input.readUint16();
    final exLen = input.readUint16();
    filename = input.readString(size: fnLen);
    extraField = input.readBytes(exLen).toUint8List();

    // Read compressedSize bytes for the compressed data.
    //_rawContent = input.subset(null, header!.compressedSize!);
    _rawContent = input.readBytes(header!.compressedSize!);

    if (password != null) {
      _initKeys(password);
      _isEncrypted = true;
    }

    // If bit 3 (0x08) of the flags field is set, then the CRC-32 and file
    // sizes are not known when the header is written. The fields in the
    // local header are filled with zero, and the CRC-32 and size are
    // appended in a 12-byte structure (optionally preceded by a 4-byte
    // signature) immediately after the compressed data:
    if (flags & 0x08 != 0) {
      final sigOrCrc = input.readUint32();
      if (sigOrCrc == 0x08074b50) {
        crc32 = input.readUint32();
      } else {
        crc32 = sigOrCrc;
      }

      compressedSize = input.readUint32();
      uncompressedSize = input.readUint32();
    }
  }
}