0

I have a series of complete, standalone zip files which have been concatenated together through a serial device; for testing purposes, one might think of cat 1.zip 2.zip 3.zip >all.zip. Now, given all.zip, I want to split that back out into separate files again—each of those being a working, standalone ZIP file with its own header.

Since ZIP files have headers that include information on file size and location, I expect there to be a reasonable mechanism by which to find the division point between these files without actually needing to parse them.

Is there a way to do this on a Unixy platform?

9
  • 1
    maybe a solution could revolve around taking the file, reading the hex, using a regex that is a pattern that matches the beginning and end of a zip file. Use the "global" modifier with the regex, which means find repeatedly. And somehow get each occurrence outputted into a file. Any programming language can do it.. Maybe perl can do it too, and perl can include command line one liners.
    – barlop
    Sep 6, 2015 at 0:59
  • @barlop, I'd consider regex a bad tool for the job, simply because something that looks like a footer can occur by pure chance inside the compressed stream. Better to use something like the Python struct module to parse out the (individual-file-record) headers and the (complete-zip-file) footers... or work back from the last footer, which should have relative indexes to content in the same file, letting one find the division point with the file above it. Sep 6, 2015 at 4:22
  • yeah something that knows the structure of zip files, would be much better than regex.. so I agree, what you suggest there sounds better. By the way, what device or prgoram exactly was it that combined the zip files one after the other like that? If it's a non-standard thing, then why would you expect there to be a command line mechanism to fix it? When most people split and combine a zip file they split it without making individual zip files.. e.g. any file splitter program. Or perhaps the method built into the program like winzip or winrar has its ways and people use that.
    – barlop
    Sep 6, 2015 at 9:38
  • So I don't see why one would expect there a command, and one that knows zip structure, to fix a zip file if it has been generated in such a non-standard way. I guess you've tried opening it in winzip, 7zip, winrar?
    – barlop
    Sep 6, 2015 at 9:38
  • @barlop, one can't reasonably expect such a command to exist for a zip file, but it's a different matter to be able to read only one datum out of a stream -- streams are a thing that exist all the time in UNIX, after all. I'll probably end up building the tool myself, but asked here in the hopes that it wouldn't be necessary. Sep 6, 2015 at 14:57

0

You must log in to answer this question.

Browse other questions tagged .