Skip to content

Replacing files within archives in place #304

@KOLANICH

Description

@KOLANICH

Description
There is a zip archive that can be large, GiBs. I need to modify a small metadata file within it. I need to do it without copying the whole archive. Modifying the file within the archive in-place is preferred and should be done this way, if it can be done. If it cannot be done I'm OK with small increase of archive size, i.e. if an additional entry is added. If I'm OK if the original file got corrupted in the case force majeures like program crashes, OS crashes, power losses.

Solution

  • Check the replacement data compressed size
  • If the size is exactly equal to the original compressed size, just overwrite and recalculate CRC
  • If the replacement is smaller, if I understand right, sections don't have to follow each other immediately, since their offsets are stored in the directory, so we can just truncate the file by changing its compressed size field, can we?
  • If the replacement is larger, can we backup the directory, add a new local header, then append the backed up directory, and fix the data in it to point to the new local header?

Describe alternatives you've considered
No

Metadata

Metadata

Assignees

No one assigned

    Labels

    won't implementWe won't implement this. If we receive usable patches, we will probably merge them.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions