LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-11-2011, 03:28 AM   #1
gabriel.560
LQ Newbie
 
Registered: Jan 2009
Posts: 17

Rep: Reputation: 0
Add files to a zip archive without having to re write the entire file?


Hi, I'm using info-zip to create zip archives. When i add files to an existing archive, the entire archive is re-written to a new temporary file and later is renamed. This means that if i have a big file and i want to add a small file to it, it will take a long time since the entire big file will be re-written. Is there any way to avoid this? like an option to append the new files to the existing archive? I've read a little about the zip archive format and it seems possible, since the zip central directory is stored at the end of the file. So theoretically you can append the last file and re-write only the zip central directory. I didn't find this option in info-zip, maybe i missed it? or maybe anyone knows another utility that can do this?

Thanks.
 
Old 09-11-2011, 03:34 AM   #2
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
The zip utility, which should be in the repository of almost any distribution can do that with its add-option.
 
Old 09-11-2011, 04:44 AM   #3
gabriel.560
LQ Newbie
 
Registered: Jan 2009
Posts: 17

Original Poster
Rep: Reputation: 0
zip utility

The "zip" and "unzip" utilities that come with Linux distributions are info-zip, and when you add files to an existing file, it re-writes the entire file to a temporary file, and finally renames it.
 
Old 09-11-2011, 05:13 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Indeed info-zip is the owner of the copyright of the zip utility. You can see it by:
Code:
zip -v
Copyright (C) 1990-2005 Info-ZIP
Type 'zip "-L"' for software license.
This is Zip 2.31 (March 8th 2005), by Info-ZIP.
To add a file to an existing archive no special option is needed. Here is an example on my system zipping a directory of about 2 Gb:
Code:
$ time zip -r LARGE_DIR.zip LARGE_DIR
<omitted>
  adding: LARGE_DIR/Data/ROMS/CDL/frc_rivers.cdl (deflated 61%)
  adding: LARGE_DIR/Data/ROMS/CDL/ini_hydro.cdl (deflated 75%)

real    2m50.099s
user    2m47.052s
sys     0m2.988s
$ time time zip LARGE_DIR.zip file1 
  adding: file1 (deflated 55%)

real    0m2.859s
user    0m0.313s
sys     0m2.450s
$ unzip -l LARGE_DIR.zip
     2389  08-30-11 09:07   LARGE_DIR/Data/ROMS/CDL/frc_rivers.cdl
     5024  08-30-11 09:07   LARGE_DIR/Data/ROMS/CDL/ini_hydro.cdl
      543  09-08-11 11:34   file1
 --------                   -------
2172913023                   2464 files
As you can see from the time required to create and then to add a single file, it could have not been recreated.
 
Old 09-11-2011, 11:21 AM   #5
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,974

Rep: Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623
I think it has to create a new file and just can't add to the old one. Where it is doing it would be my guess memory unless you don't have enough. It isn't exactly like a tar process. A zip will recompute checksum. Pretty sure pk-zip did it that way a long time ago.

From man.

"When changing an existing zip archive, zip will write a temporary file with the new contents, and only replace the old one when the process of creating the new version has been completed without error."
 
Old 09-13-2011, 01:41 AM   #6
gabriel.560
LQ Newbie
 
Registered: Jan 2009
Posts: 17

Original Poster
Rep: Reputation: 0
So it's not possible with info-zip. Thanks.
 
Old 09-13-2011, 10:09 AM   #7
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,776

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Quote:
Originally Posted by colucix View Post
As you can see from the time required to create and then to add a single file, it could have not been recreated.
Keep in mind that when recreating the file, zip does not need to re-compress the original files, just copy the already-compressed data. That is likely to take far less time than it took to create the original archive. Unlike gzip, which compresses the entire content as a single unit, zip independently compresses each file in the archive, and indeed the files in a single archive could use different compression methods.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Linux zip program's -d -tt option deletes all files from zip archive Arun Gupta Linux - Software 4 04-27-2011 07:06 PM
[SOLVED] Add | insert one file to multi .zip files? ZendVN Linux - Newbie 2 10-28-2009 06:05 AM
how to add a file to a zip, without including the entire path from root marvelade Linux - Newbie 6 02-19-2009 05:32 AM
Archive manager not recognising ZIP files - suggests it's a text file. AnanthaP Ubuntu 4 12-27-2007 07:10 AM
Script to Add files to a Zip archive with out unzipping it !! prashix Programming 12 10-23-2007 09:19 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:44 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration