I have a routine running in production for a couple of years now. It's about heavy manipulation of OOXML-files. These are, as you know, zip-files.

I have a routine running in production for a couple of years now. It's about heavy manipulation of OOXML-files. These are, as you know, zip-files.

I was using TZipFile with this hack:

http://stackoverflow.com/questions/13164299/delphi-xe2-tzipfile-replace-a-file-in-zip-archive

(see the top answer). This has been working very good.

But when moving to Berlin we cannot access private members like that anymore. And i need to write, delete, write delete numerous times for the same archive.

So i installed Abbrevia using getIt. And changed my code to use it instead. That was not difficult. However, i run into this for the more complex runs:

https://sourceforge.net/p/tpabbrevia/bugs/158/

The suggested workaround does not do it for me. I get the same results with or without :(

Tried to figure out the status of it all, but i do not have the full picture. Anyone here knows some more about it?

Or; if someone could point me to another Zip-lib. I'll be using streams, for manipulation.
http://stackoverflow.com/questions/13164299/delphi-xe2-tzipfile-replace-a-file-in-zip-archive

Comments

  1. I'm surprised that you have a need to remove files. Without knowing more about why you want to do that, I'd wonder if a better solution isn't to design the system so that you never need to remove files.

    ReplyDelete
  2. Jeroen Wiert Pluimers it's a hash table and it's convoluted and no one else seems to have been able to do that since 2003. I did some feeble tries, but i will not be able to provide an absolutely ok fix during the time-span i have for this :(

    David Heffernan It's OOXML. Yes, there are situations where i need to delete a file from the archive. Much much more common is the need to overwrite a file. With the hack, an overwrite is a delete and an add. That goes for Abbrevia too.

    So when i need to do several updates of relation and content files they will be deleted and added. As you say i could redesign the whole thing to pick up everything uncompressed in memory, manipulate and then write it back.

    But juggling the time for re-coding and the (eventual) performance gain - i'd really like to keep the nested style of this routine - things become much simpler.

    Also, to manipulate the archive as has been done works extremely well. It's a reported but not confirmed bug in Abbrevia that stopped me.

    As a last resort, i have of course been contemplating this. I'm keeping this whole system kind of "clean" so no MS SDK DLLs (OOXML SDK could do it all) but i do not like the coding style they use (everything is a class).

    A. Bouchez, tanks! I will check it out at once.

    ReplyDelete
  3. It sounds like you're trying to use a ZIP file container to simulate a file system. Have you considered using a real file system component instead? EldoS has one called Solid File System. They have this in their description:

    "Similar to ZIP files SolFS compresses the data and stores everything in one container. But unlike ZIP format SolFS was designed for easy rewriting of files in the container, so writing and deletion operations are fast and don't require rewriting of the whole container file."

    Unfortunately, their licensing options look like a maze.

    I think there are a couple others available as well (eg., Single File System from AidAim, but they seem to have become somewhat of a zombie site.)

    Another link I found quickly:

    http://stackoverflow.com/questions/1454299/simple-virtualfilesystem-for-delphi-must-be-free

    stackoverflow.com - simple VirtualFilesystem for delphi - must be FREE!

    ReplyDelete
  4. David Schwartz, yes, you could say that. If i decide to redesign it using recommendations from David Heffernan and you i wont't need more components :)

    ReplyDelete
  5. David Schwartz The OOXML specification dictate that they are zip files, so he can't change that part.

    ReplyDelete
  6. I did check out the SDK before writing my own thingy. It really looks like MS is doing the same thing, but i did not dig deep enough. One could extract it all to the same structure and then pack everything up again. Rather not do that kind of change ATM.

    ReplyDelete
  7. I messed with something similar years ago and seem to recall that any time you update the file index of a ZIP file you need to save it, which flushes the whole thing out to disk or a memory-based filestream. And it's not generally possible to replace files because they're like a large collection of arrays with fixed starting indices and fixed lengths.

    ReplyDelete
  8. If only accessing TZipFile private members is the problem... why not making a copy of that unit in your project and add your delete function?

    ReplyDelete
  9. Accessing private members in Berlin is possible with some hacks.

    ReplyDelete
  10. Cristian Peța, i wanted to refrain from all that must be checked when there are upgrades. But in this case, maybe you suggestion is the most cost effective for me at the moment. Considering Emba probably won't do much with the TZipFile class in the (near) future.

    ReplyDelete

Post a Comment