Uploaded image for project: 'Commons Compress'
  1. Commons Compress
  2. COMPRESS-395

[Zip] Do not add data descriptor record when CRC and size values are known

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • None
    • 1.15
    • Archivers

    Description

      Hi,

      Currently ZipArchiveOutputStream will add data descriptor record when the output do not provide random access. But if you add an entry using addRawArchiveEntry then the CRC, compressed size and uncompressed size could be know and there is no need for data descriptor record as those values could be set in the local file header. The current implementation does both - it sets the correct value in the local file header and adds additional data descriptor record. Here is the relevant code from ZipArchiveOutputStream#putArchiveEntry:

                  // just a placeholder, real data will be in data
                  // descriptor or inserted later via SeekableByteChannel
                  ZipEightByteInteger size = ZipEightByteInteger.ZERO;
                  ZipEightByteInteger compressedSize = ZipEightByteInteger.ZERO;
                  if (phased){
                      size = new ZipEightByteInteger(entry.entry.getSize());
                      compressedSize = new ZipEightByteInteger(entry.entry.getCompressedSize());
                  } else if (entry.entry.getMethod() == STORED
                          && entry.entry.getSize() != ArchiveEntry.SIZE_UNKNOWN) {
                      // actually, we already know the sizes
                      size = new ZipEightByteInteger(entry.entry.getSize());
                      compressedSize = size;
                  }
                  z64.setSize(size);
                  z64.setCompressedSize(compressedSize);
      

      Maybe ZipArchiveOutputStream could be improved to not add data descriptor record when the CRC and size values are known in advance.

      Attachments

        Activity

          People

            Unassigned Unassigned
            plamenttv Plamen Totev
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: