Skip to main content.
home | support | download

Back to List Archive

Re: MIME Types of zipped files

From: Bill Moseley <moseley(at)>
Date: Wed Nov 09 2005 - 14:43:02 GMT
On Wed, Nov 09, 2005 at 05:59:34AM -0500, Lars D. Noodén wrote:
> On Fri, 4 Nov 2005, Bill Moseley wrote:
> >... The filters register regular expressions of mime types they handle. 
> >If the incoming document matches the filters mime type then the filter 
> >is passed the incoming content.
> Zipped or otherwise compressed files all have the same apparent MIME type 
> until they are actually unzipped.  How is that best resolved in

$ file test.sxw
test.sxw: Zip archive data, at least v2.0 to extract

$ perl -MMIME::Types -wle 'print MIME::Types->new->mimeTypeOf("test.sxw")'

> >... One things the filters are not setup to do is to take a single file
> >(like a tar or zip file) and then index those as separate files.  It
> >should do that, but it doesn't.
> Ok.  That's what I'm trying to set up.  Files in OpenDocument format are 
> really a collection of files and a few directories.  The three files 
> relevant for indexing are mimetype, content.xml and meta.xml, but they 
> cannot be seen until the whole thing is processed with unzip.

But that's different than a zip or tar archive that contains multiple
documents.  This is a single document made up of different parts, so
that's ok.

The process in the filter will be to look for 'application/vnd.sun.xml.writer'
Then use a perl module to extract out the content from the content.xml
part.  Then merge in the tags from meta using a XML processing module.
Then that is the output from the filter.

I'd take a a look at a few things on CPAN:

But you may just need:

    use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
    my $zip = Archive::Zip->new( 'test.sxw' );
    print $zip->contents( 'content.xml' );

Of course, you would do error checking, which I left out.
That would be more portable than, say:

    unzip -c test.sxw content.xml

And then use some XML processing module to merge the meta.xml and
content.xml into a single xml file.  Perhaps:

I think you will want to extract out the text content.  Maybe that
OODoc Perl module would help with that (I have never used that
module).  I'm not sure how you would know what all <text:> tags to
extract in a general case.  Maybe in the OO format tag content is
always the doc content???

Same with the meta.xml file.  You may also want to convert the ISO dates to
unix time stamps in some cases.

Keep in mind that OO files are utf8 -- so you won't be able to index
all characters.

Finally, the "tidy" program might be useful when working on this:

$ tidy -xml meta.xml

line 1 column 1 - Access: []: <doctype> missing.
line 1 column 1 - Access: []: use style sheets to control presentation.

<?xml version="1.0" encoding="utf-8"?>
office:document-meta PUBLIC "-// OfficeDocument 1.0//EN"
<office:document-meta xmlns:office=""
xmlns:meta="" office:version="1.0">
        <meta:generator> 1.1.4 (Linux)</meta:generator>
        <meta:user-defined meta:name="Info 1" />
        <meta:user-defined meta:name="Info 2" />
        <meta:user-defined meta:name="Info 3" />
        <meta:user-defined meta:name="Info 4" />
        <meta:document-statistic meta:table-count="0" meta:image-count="0"
        meta:object-count="0" meta:page-count="1"
        meta:paragraph-count="21" meta:word-count="463"
        meta:character-count="2476" />

Bill Moseley

Unsubscribe from or help with the swish-e list:

Help with Swish-e:
Received on Wed Nov 9 06:43:03 2005