Difference between revisions of "Archive Module"

From BaseX Documentation
Jump to navigation Jump to search
Line 8: Line 8:
 
=Functions=
 
=Functions=
  
==zip:create==
+
==zip2:create==
 
{|
 
{|
 
|-
 
|-
 
| width='90' | '''Signatures'''
 
| width='90' | '''Signatures'''
|{{Func|zip:create|$entries as element(entry)*, $contents as item()*|xs:base64Binary}}<br />
+
|{{Func|zip2:create|$entries as element(entry)*, $contents as item()*|xs:base64Binary}}<br />
 
|-
 
|-
 
| '''Summary'''
 
| '''Summary'''
|Creates a new ZIP archive from the specified entries and contents.
+
|Creates a new ZIP archive from the specified entries and contents.<br/>The {{Code|$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. An Example:
The {{Mono|$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.
+
<pre class="brush:xml">
The actual {{Mono|$contents}} must be {{Mono|xs:string}} or {{Mono|xs:base64Binary}} items.
+
<entry last-modified='2011-11-11T11:11:11'
 +
      compression-level='9'
 +
      encoding='US-ASCII'>hello.txt</entry>
 +
</pre>
 +
The actual {{Code|$contents}} must be {{Code|xs:string}} or {{Code|xs:base64Binary}} items.
 
|-
 
|-
 
| '''Errors'''
 
| '''Errors'''
|{{Error|FOZ20001|#Errors}} the number of entries and contents differs.<br />{{Error|FOZ20002|#Errors}} (some of) the contents are not strings or binaries.<br />{{Error|FOZ20003|#Errors}} (some of) the entries elements contain invalid data.<br/>{{Error|FOZ20004|#Errors}} the specified encoding is invalid or not supported.<br/>{{Error|FOZ29999|#Errors}} archive processing failed for some other reason.
+
|{{Error|FOZ20001|#Errors}} the number of entries and contents differs.<br />{{Error|FOZ20002|#Errors}} (some of) the contents are not of type {{Code|xs:string}} or {{Code|xs:base64Binary}}.<br />{{Error|FOZ20003|#Errors}} entries elements contain invalid data.<br/>{{Error|FOZ20004|#Errors}} the specified encoding is invalid or not supported.<br/>{{Error|FOZ29999|#Errors}} archive processing failed for some other reason.
 
|-
 
|-
 
| '''Examples'''
 
| '''Examples'''
|The following function creates a file {{Code|archive.zip}} with the file {{Code|file.txt}} inside:
+
|The following function creates an archive {{Code|archive.zip}} with one file {{Code|file.txt}}:
<pre class="brush:xquery">
 
zip:create(
 
  <file xmlns="http://expath.org/ns/zip" href="archive.zip">
 
    <entry src="file.txt"/>
 
  </file>)
 
</pre>
 
The following function creates a file {{Code|archive.zip}}. It contains one file {{Code|readme}} with the content "{{Code|thanks}}":
 
 
<pre class="brush:xquery">
 
<pre class="brush:xquery">
zip:zip-file(
+
zip2:create(<entry>file.txt</entry>, 'Hello World')
  <file xmlns="http://expath.org/ns/zip" href="archive.zip">
 
    <entry name="readme">thanks</entry>
 
  </file>)
 
 
</pre>
 
</pre>
 
|}
 
|}
  
 
[[Category:XQuery]]
 
[[Category:XQuery]]

Revision as of 21:04, 28 May 2012

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

zip2:create

Signatures zip2: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. An Example:
<entry last-modified='2011-11-11T11:11:11'
       compression-level='9'
       encoding='US-ASCII'>hello.txt</entry>

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 of type xs:string or xs:base64Binary.
FOZ20003: entries elements contain invalid data.
FOZ20004: the specified encoding is invalid or not supported.
FOZ29999: archive processing failed for some other reason.
Examples The following function creates an archive archive.zip with one file file.txt:
zip2:create(<entry>file.txt</entry>, 'Hello World')