Adding new files to Zip archive

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Aladdin

    Adding new files to Zip archive

    I am using the java.util.zip package to create zip files. I can
    create a new archive and add files to it without any trouble. But if
    I already have a zip file created, how do I add a new file to the
    archive without impacting the existing files? I looked through the
    APIs with no luck. I would rather avoid extracting all the files and
    rebuilding the archive from scratch if at all possible.

    Thanks

    -M
  • Chris

    #2
    Re: Adding new files to Zip archive

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    Aladdin wrote:
    [color=blue]
    > I am using the java.util.zip package to create zip files. I can
    > create a new archive and add files to it without any trouble. But
    > if I already have a zip file created, how do I add a new file to the
    > archive without impacting the existing files? I looked through the
    > APIs with no luck. I would rather avoid extracting all the files
    > and rebuilding the archive from scratch if at all possible.
    >
    > Thanks
    >
    > -M[/color]

    Hi,
    I'm not familiar with the internal format of a ZIP file, but
    rebuilding the file from scratch may be the only way any program can
    do it. I'm not sure. I was interested, so I created a ZIP with two
    files in it just now to look at. It seems that the files' data is
    placed, along with the filenames, into the ZIP, and that immediately
    following the last file is a table of contents with all the
    filenames. This would imply that you cannot add data to a ZIP without
    at least loading the table of contents, overwriting it, and rewriting
    it at the new end of file. Anyway, if nobody comes up with a better
    solution, remember that it's probably better to create a new,
    temporary ZIP file, then transfer all the files via an in-memory
    array from the old to the new, followed by finally placing your new
    file in the new ZIP. This is probably faster than the other option,
    which would be extracting all the contents of the old ZIP to actual
    files, deleting it, then replacing it.

    - --
    Chris
    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.2.2 (GNU/Linux)

    iD8DBQE/RTDxwxczzJRavJY RAlh0AKD27GEvLc I/Fg+jHYpiBYpndnK b/ACfcS7t
    cZrygAi8TLOh18I bgYcU7c0=
    =F5kv
    -----END PGP SIGNATURE-----

    Comment

    Working...