• Post Reply Bookmark Topic Watch Topic
  • New Topic

Archiving question  RSS feed

 
Matthew David
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello guys, I need some help.
Basically I'd like to store some files in an archive file (like a zip file), for easier handling. While my program runs, it has to access some of the files (not all of them once, max. 2-3 at a time), and sometimes modify them. Accessing files is easy using zip files, but for modifying them, I have to recreate the whole file. And I don't want to unpack the files, and then repack them when the program closes, if it's not necessary. Do you have any ideas? My google-fu failed me.
Thanks, Rothens
 
Tony Docherty
Bartender
Posts: 3209
78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you modify a file in a zip you have to rebuild the zip, there's no way around it that I know of.

You don't necessarily need to unpack the zip on startup and then repack it on shutdown though (although if you are doing many modifications it may be the most efficient way). You can read the contents of the zip file and write each file out to the new zip on the fly substituting the modified file for the new version as you go.
 
Matthew David
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tony Docherty wrote:If you modify a file in a zip you have to rebuild the zip, there's no way around it that I know of.


I do not insist using zip files, but that was my only idea so far. But if there's any other method for the scenario, I would gladly use that.
 
Henry Wong
author
Sheriff
Posts: 22861
119
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my opinion, any file format that compresses or encrypts the information, will need to be extracted and rewritten for changes. Heck, even if you don't use compression (or encryption), meaning if you just use a raw file, the file will still have to be rewritten, if the changes are not the same size as the original.

Arguably, you can use some sort of change file, which record changes at the end of the file... however, this file will keep getting longer and longer, and eventually, will need some some of processing to get the list of changes back into a snapshot.

Henry
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not "easier handling" if you have to rebuild the entire zip archive just to change a line in one file, is it? It's quite likely "easier distribution", as you can just take the whole zip file and plop it down in a convenient location.

But anyway, what I would suggest is this: Get the file out of the archive when you want to use it. If it needs to be changed, store the changed version in the user's directory. Then the next time you need to use the file, check first to see if there's a changed version before looking in the zip archive for the file.

You can get the user's home directory from the system property "user.home". You might want to create a subdirectory there for your application to store these files.
 
Omar Rashwan
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this may be will help

Zip FileSystem Provider
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!