ZIP Module: First Proposal

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

ZIP Module

The following is a first proposal for an XQuery ZIP Module.

Open issues:

  1. namespace of the module
  2. what kind of options/how does the $options node look like (schema needed)
  3. how to handle updates to zip archives (e.g. have functions for updates, deletes, inserts instead of one modify function that does everything)
  4. working directly with files
possible solution
new zip-file module containing symmetric functions but taking URIs instead of xs:base64Binary as parameters
zip-file module could be implement directly in XQuery using EXPath file and this ZIP module
more efficient implementation possible if done externally
module namespace zip = "http://www.zorba-xquery.com/modules/zip";
(:~
 : Create a new zip archiving according to the given spec.
 : The content can be either string or base64Binary.
 :
 : <parts compression-level="9">
 :   <part last-modified="" compress="false">
 :     myfile.txt
 :   </part>
 :   <part>
 :     dir/myfile.xml
 :   </part>
 :   <part>
 :     dir/dir2/image.png
 :   </part>
 : </parts>
 :
 : @return a streamable base64
 :
 : @error if number of parts is not equal to count($content)
 :)
declare function zip:create($spec as node(), $content) as xs:base64Binary external;

(:~
 : Return the archive format of the given zip archive.
 :
 : <parts>
 :   <part last-modified="2009-03-20T03:30:32" compressed-size="232" uncompressed-size"324" encrypted="false">
 :     myfile.txt
 :   </part>
 :   <part>
 :     dir/myfile.xml
 :   </part>
 :   <part>
 :     dir/dir2/image.png
 :   </part>
 : </parts>
 :)
declare function zip:entries($zip as xs:base64Binary) as node() external;

(:~
 : Return the archive format of the given zip archive.
 : 
 : Possible options: repair: true, false
 :)
declare function zip:entries($zip as xs:base64Binary, $options as node()) as node() external;

(:~
 : Return the entry identified by the given name from the zip archive
 : as a string.
 : The default encoding used to read the string is UTF-8.
 :
 : @return a streamable string
 :
 : @error if the file contains invalid utf-8 characters
 : @error if the file doesn't exist
 :)
declare function zip:extract-text-entry($zip as xs:base64Binary, $name as xs:string) as xs:string
{
  zip:text-entry($zip, $name, <options/>)
};

(:~
 : Return the entry identified by the given name from the zip archive
 : as a base64Binary.
:
 : @return a streamable base64
 :
 : @error if the file doesn't exist
 :)
declare function zip:extract-binary-entry($zip as xs:base64Binary, $name as xs:string) as xs:base64Binary
{
  zip:binary-entry($zip, $name, <options/>)
};

(:~
 : Return the entry identified by the given name from the zip archive
 : as a string.
 :
 : Possible options: 
 :   repair: true, false
 :   encoding
 :
 : @return a streamable string
 :
 : @error if the file contains invalid utf-8 characters
 : @error if a transcoding error happens
 :)
declare function zip:extract-text-entry($zip as xs:base64Binary, $name as xs:string, $options as node()) as xs:string external;

(:~
 : Return the entry identified by the given name from the zip archive
 : as a string.
 :
 : Possible options: 
 :   repair: true, false
 :
 : @return a streamable base64
 :
 : @error if the file doesn't exist
 :)
declare function zip:extract-binary-entry($zip as xs:base64Binary, $name as xs:string, $options as node()) as xs:base64Binary external;
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox