Archive Module: Seventh Proposal

From Spex: Specifications for XQuery Modules
Jump to: navigation, search

Yet another proposal for the Archive Module:

  • added create#3 functions allowing to specify options + a schema for the options

The full function signatures are as follows:

(: Module namespace is still subject to change. :)
module namespace archive = "http://www.expath.org/ns/archive";

import schema namespace options = "http://www.expath.org/ns/archive";
 
(:~
 : Create a new archive according to the given spec.
 : The contents can be string and base64Binary items.
 :
 : Example:
 : <!-- specify compression level (0 = uncompressed) -->
 : <entry last-modified="" compression-level="0">
 :   myfile.txt
 : </entry>
 : <!-- specify encoding for text entries -->
 : <entry encoding="Shift_JIS">
 :   dir/myfile.xml
 : </entry>
 : <entry>
 :   dir/dir2/image.png
 : </entry>
 :
 : @return a base64Binary 
 :
 : @error if the number of entry elements differs from the number
 :        of specified contents: count($entries) ne count($contents)
 : @error if an encoding is specified and the item is a base64Binary
 :)
declare function archive:create($entries as element(entry)*, $contents as item()*)
    as xs:base64Binary external;

(:~
 : <archive:options archive-format="zip">
 :   <archive:compression algorithm="stored"/>
 : </archive:options>
 :)
declare function archive:create(
  $entries as element(entry)*,
  $contents as item()*,
  $options as element(archive:options))
  as xs:base64Binary external;
 
(:~
 : Return the specification of the given archive.
 :
 : Example:
 : <entry last-modified="2009-03-20T03:30:32" compressed-size="232" uncompressed-size"324" encrypted="false">
 :   myfile.txt
 : </entry>
 : <entry>
 :   dir/myfile.xml
 : </entry>
 : <entry>
 :   dir/dir2/image.png
 : </entry>
 :
 : @return specification
 :)
declare function archive:entries($archive as xs:base64Binary)
    as element(entry)* external;
 
(:~
 : Returns all entries from the archive as a string.
 : The default encoding used to read the string is UTF-8.
 :
 : @return strings
 :
 : @error if the file contains invalid utf-8 characters
 : @error if the file doesn't exist
 :)
declare function archive:extract-text($archive as xs:base64Binary)
    as xs:string* external;
 
(:~
 : Returns the entries identified by the given paths from the archive
 : as a string.
 : The default encoding used to read the string is UTF-8.
 :
 : @return strings
 :
 : @error if the file contains invalid utf-8 characters
 : @error if the file doesn't exist
 :)
declare function archive:extract-text($archive as xs:base64Binary, $entry-names as xs:string*)
    as xs:string* external;
 
(:~
 : Returns the entries identified by the given paths from the archive
 : as a string.
 :
 : @return strings
 :
 : @error if the file contains invalid characters
 : @error if a transcoding error happens
 :)
declare function archive:extract-text($archive as xs:base64Binary, $entry-names as xs:string*, $encoding as xs:string)
    as xs:string* external;
 
(:~
 : Returns all entries from the archive
 : as base64Binary.
 :
 : @return base64Binary items
 :
 : @error if the file does not exist
 :)
declare function archive:extract-binary($archive as xs:base64Binary)
    as xs:base64Binary* external;
 
(:~
 : Returns the entries identified by the given paths from the archive
 : as base64Binary.
 :
 : @return base64Binary items
 :
 : @error if the file does not exist
 :)
declare function archive:extract-binary($archive as xs:base64Binary, $entry-names as xs:string*)
    as xs:base64Binary* external;
 
(:~
 : Adds and replaces entries in a archive according to
 : the given spec. The contents can be string and base64Binary items.
 :
 : @return the updated base64Binary
 :
 : @error if the number of entry elements differs from the number
 :        of specified contents: count($entries) ne count($contents)
 :
 :)
declare function archive:update($archive as xs:base64Binary, $entries as element(entry)*, $contents as item()*)
    as xs:base64Binary external;
 
(:~
 : Deletes entries from a archive.
 :
 : @return the updated base64Binary
 :
 : @error if an addressed entry does not exist
 :)
declare function archive:delete($archive as xs:base64Binary, $entry-names as xs:string*)
    as xs:base64Binary external;

The options schema is follows:

<?xml version="1.0"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
  targetNamespace="http://www.expath.org/ns/archive"
  xmlns="http://www.expath.org/ns/archive"
  elementFormDefault="qualified"
  attributeFormDefault="unqualified">

  <xs:element name="options">
    <xs:complexType>
      <xs:all>
        <xs:element name="compression" type="compression-type"/>
      </xs:all>
      <xs:attributeGroup ref="option-attributes"/>
    </xs:complexType>
  </xs:element>

  <xs:attributeGroup name="option-attributes">
    <xs:attribute name="archive-format" type="format-type" default="zip"/>
  </xs:attributeGroup>

  <xs:simpleType name="format-type">
    <xs:restriction base="xs:string">
      <xs:enumeration value="zip"/>
      <xs:enumeration value="tar"/>
      <xs:enumeration value="pax"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:complexType name="compression-type">
    <xs:attributeGroup ref="compression-attributes"/>
  </xs:complexType>

  <xs:attributeGroup name="compression-attributes">
    <xs:attribute name="level" type="xs:integer" default="5"/>
    <xs:attribute name="algorithm" type="algorithm-type" default="deflate"/>
  </xs:attributeGroup>

  <xs:simpleType name="algorithm-type">
    <xs:restriction base="xs:string">
      <xs:enumeration value="stored"/>
      <xs:enumeration value="deflate"/>
      <xs:enumeration value="bzip2"/>
      <xs:enumeration value="lzma"/>
    </xs:restriction>
  </xs:simpleType>

</xs:schema>

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox