ZIP Module: Fifth Proposal

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

Yet another proposal for the ZIP Module:

  • Proposed by Matthias: argument $entries as element(entries) changed to $entries as element(entry)*
  • extract functions may now return more than a single item
  • extract functions with one signature added (will return all contents)
  • update functions reduced to zip:update() (for adding and replacing) and zip:delete()

The full function signatures are as follows:

module namespace zip = "http://www.expath.org/ns/zip2";
(:~
 : Create a new zip archiving 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 zip:create($entries as element(entry)*, $contents as item()*)
    as xs:base64Binary external;

(:~
 : Return the specification of the given zip 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 zip:entries($zip as xs:base64Binary)
    as element(entry)* external;

(:~
 : Returns all entries from the zip 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 zip:extract-text($zip as xs:base64Binary)
    as xs:string* external;

(:~
 : Returns the entries identified by the given paths from the zip 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 zip:extract-text($zip as xs:base64Binary, $entry-names as xs:string*)
    as xs:string* external;

(:~
 : Returns the entries identified by the given paths from the zip archive
 : as a string.
 :
 : @return strings
 :
 : @error if the file contains invalid characters
 : @error if a transcoding error happens
 :)
declare function zip:extract-text($zip as xs:base64Binary, $entry-names as xs:string*, $encoding as xs:string)
    as xs:string* external;

(:~
 : Returns all entries from the zip archive
 : as base64Binary.
 :
 : @return base64Binary items
 :
 : @error if the file does not exist
 :)
declare function zip:extract-binary($zip as xs:base64Binary)
    as xs:base64Binary* external;

(:~
 : Returns the entries identified by the given paths from the zip archive
 : as base64Binary.
 :
 : @return base64Binary items
 :
 : @error if the file does not exist
 :)
declare function zip:extract-binary($zip as xs:base64Binary, $entry-names as xs:string*)
    as xs:base64Binary* external;

(:~
 : Adds and replaces entries in a zip 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 zip:update($zip as xs:base64Binary, $entries as element(entry)*, $contents as item()*)
    as xs:base64Binary external;

(:~
 : Deletes entries from a zip archive.
 :
 : @return the updated base64Binary
 :
 : @error if an addressed entry does not exist
 :)
declare function zip:delete($zip as xs:base64Binary, $entry-names as xs:string*)
    as xs:base64Binary external;
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox