Tuesday 7 October 2014

ODF Explode and ReZip Fails

I thought I'd do a very basic test first by unzipping an ODT file to see what was inside it, and then rezip it into a new ODT file.

This failed. I'm trying to work out why.

The following should work:
  1. Save simple ODT from Google Docs (or LibreOffice) test.odt
  2. Rename test.odt to test.zip and unzip it to a folder test/
  3. Explore the contents of the test/ folder which contains stuff like contents.xml and a manifest.xml
  4. Don't make any changes to any xml files
  5. Rezip the test/ folder as test1.zip, rename it to test1.odt
  6. Open it using LibreOffice.
Step 6 fails with LibreOffice reporting a corrupted document. I'll need to find out why. It could be a timestamp or some kind of hash that is part of the zip structure.

UPDATE - the issue seems to be the file path ames of the entries in the zipped file which should not include the folder name itself.  That is folder/file.xml is bad, but file.xml is ok. If you create a zip from within the unzipped folder, that works. That is, if you create test1.zip from within the test/ folder the resultant test1.zip can be renamed test1.odt and that file opens fine.

3 comments:

  1. I think this is a bit confused. Zip tends to create file paths relative to the directory you are starting in. That is why you need to start in the "root" directory of the document, the one with top-level parts such as content.xml, styles.xml, mimetype, etc. In that way, files in subfolders, such as META-INF/manifest.xml will be picked up with the proper root-relative path full path names. (The Zip package actually stores path names for files and does not have any inherent folder structure, but the Zip utilities simulate folders to line up with how import and extract work on the usual platforms.)

    ReplyDelete
  2. If you have a Utility like WinZip or 7-Zip installed, there is an easier way to inspect ODF (and OOXML) files. Right click on the document file (e.g., test.odt) and use Open With ... to select that utility for opening the document. (Remove any checked-box for changing the default application.) In the future, Windows will have remembered that you also use this utility to open such documents and Open With will offer that as an option along with the established default. (If the default gets changed by mistake, just use OpenWith ... to change it back.)

    ReplyDelete
  3. Thanks orcmid for your helpful comments - very useful!

    ReplyDelete