Author Topic: How to efficiently query filesize of all contained files in a ZIP file ?  (Read 191 times)

Lars

  • Hero Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 60
  • Posts: 581
    • View Profile
I am writing a small tool (or rather, a DLL routine that integrates into the VAC workframe) to search in each archive file of a ZIP file if it contains a keyword/keystring or not.
The first approach was to unzip each archive file from the ZIP to stdout via "unzip -p" and pipe into "find" which then searches for the keyword and gives the proper return code if the keyword was found or not.
That worked but was incredibly slow (for the ZIP file size I was working on). I now decided to run "unzip -c" on the complete ZIP and pipe the output into memory. The "-c" instead of the "-p" will also add the archive names, preceding the archive content, which provides the discriminator to individually search each archive content for the keystring.
The problem is that I need to allocate enough memory for the unzipped content. I just allocated 100 MB (which is eventually freed) but that is potentially a large waste of memory.
Is there an easy and efficient way to determine the overall sum size of the UNZIPPED archive files contained in a ZIP file ?
I need something that I can integrate into an application, not a standalone solution.
« Last Edit: July 12, 2020, 11:03:39 am by Lars »

Lars

  • Hero Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 60
  • Posts: 581
    • View Profile
Looks like "unzip -Z -t" gives me the info I am looking for.