Archive Module

From BaseX Documentation
Revision as of 19:41, 28 May 2012 by CG (talk | contribs) (Created page with "This XQuery Module contains functions to handle ZIP archives. New ZIP archives can be created, existing archives can be updated, and the archive entries can be...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This XQuery Module contains functions to handle ZIP archives. New ZIP archives can be created, existing archives can be updated, and the archive entries can be listed and extracted. This module may eventually replace the existing ZIP Module as soon as it is finalized and adopted by other XQuery implementations.

Conventions

All functions in this module are assigned to the http://basex.org/modules/zip2 namespace, which is statically bound to the zip2 prefix.
All errors are assigned to the http://basex.org/errors namespace, which is statically bound to the bxerr prefix.

Functions

zip:create

Signatures zip:create($entries as element(entry)*, $contents as item()*) as xs:base64Binary
Summary Creates a new ZIP archive from the specified entries and contents.

The $entries elements contain meta information required to create new ZIP entries. Beside the mandatory entry name, optional attributes can be specified, which contain the timestamp, compression level and encoding of textual entries. The actual $contents must be xs:string or xs:base64Binary items.

Errors FOZ20001: the number of entries and contents differs.
FOZ20002: (some of) the contents are not strings or binaries.
FOZ20003: (some of) the entries elements contain invalid data.FOZ20004: the specified encoding is invalid or not supported.
FOZ2999: archive processing failed for some other reason.
Examples The following function creates a file archive.zip with the file file.txt inside:
zip:create(
  <file xmlns="http://expath.org/ns/zip" href="archive.zip">
    <entry src="file.txt"/>
  </file>)

The following function creates a file archive.zip. It contains one file readme with the content "thanks":

zip:zip-file(
  <file xmlns="http://expath.org/ns/zip" href="archive.zip">
    <entry name="readme">thanks</entry>
  </file>)