- 
                Notifications
    You must be signed in to change notification settings 
- Fork 18.4k
Closed
Description
If you have a compressed file, know its uncompressed size and crc32 checksum, it'd be nice to be able to add it to an archive as is.
I have three current use-cases for this:
- Repackaging a zip file, removing or adding files, without incurring the associated compression overheads for files that already exist (somewhat achieving proposal: archive/zip: add support for appending files #15626)
- Compress first and include later based on whether the compressed size was smaller than the original, without having to perform the compression twice.
- Support concurrent compression: compress many files concurrently and then copy the already compressed files to the archive (similar to Apache Commons Compress' ParallelScatterZipCreator)
I see three different ways we could achieve this:
- Create a zip.CreateHeaderRaw(fh *FileHeader) (io.Writer, error)function, that uses the FileHeader'sCRC32andUncompressedSize64fields set by the user.
- Use the existing CreateHeader(fh *FileHeader) (io.Writer, error)function, but have a new FileHeader field that indicates we're going to write already compressed data (and then useCRC32andUncompressedSize64fields set by the user)
- Use the existing CreateHeader(fh *FileHeader) (io.Writer, error)function, but ifCompressedSize64has already been set, assume that data written is already compressed.
I'm going to assume that option 3 would be a no-go, because existing code might suddenly break if a user has already set the CompressedSize for whatever reason, but hopefully the other options are viable.