Hi there !

Andy Pitonyak wrote:
Is it possible to construct a zip file from the extracted contents of
an ods or odt file that is identical to the original ods/odt file?  I
would like to be able to do something like the following:

$ unzip doc.odt -d doc
$ cd doc
$ zip [options] ../doc2.zip *
$ diff ../doc.odt ../doc2.zip && echo match
match

I tried the following with [options] being -9Xr, but the resulting zip
file was 7163 bytes and the original odt was 6741 bytes.

I've attempted to determine the sequence of operations that OOo uses
to create its zip files by analyzing the source code, but I haven't
figured out exactly how it does it.  There seems to be some
compression going on in AddXMLAsZipToTheStorage in
binfilter/bf_sfx2/source/doc/sfx2_objstor.cxx, which uses the ZCodec
class implemented in tools/source/zcodec/zcodec.cxx (which in turn
uses zlib), but I'm not sure if this is the code that handles all the
zip file stuff and I don't know where it gets the list of files to
compress.

Does someone know of a set of zlib operations that will produce a zip
file identical to the one OOo produces?  Or is there a set of options
I can pass to a common zip command-line tool that will do this?


Basically there is just one catch when creating ODF files by zipping with command line tools, zlib or similar. There is a "mimetype" stream defined in the ODF specification and the specification states "This stream should be first stream of the package's zip file, it shall not be compressed, and it shall not use an 'extra field' in its header". It should be possible to create a file that follows this rule using zip(1) though eg. by using two command lines the first one creating the zip file by storing just the "mimetype" file as an uncompressed entry and a second one adding everything else using normal compression.


This has been discussed to some extent before
(http://www.openoffice.org/servlets/BrowseList?list=dev&by=thread&from=1243563),
but it was specifically in relation to storing OOo files in
Subversion, which is in the end what I'm interested in.  It would be
nice to commit OOo files to Subversion, have it store the XML files
individually, and then get it to reproduce an identical OOo file from
the XML files when a user checks it out.


If you insist that the generated zip file is the same, then you likely
need to use their API to create it. In general, it should not matter if
the generated file is identitical, just that it is valid.


Agreed it just matters that it´s valid and for this the XML content must be valid according to the ODF spec and that "mimetype file is stored as uncompressed and first content in zip file" - rule must be followed.

Kind regards,
Bernd Eilers


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to