Changes

Jump to navigation Jump to search
788 bytes removed ,  18:38, 1 December 2023
m
Text replacement - "syntaxhighlight" to "pre"
{| width='100%'
|- valign="top"
| width='120' | '''SignaturesSignature'''|{{Func|<pre>archive:entries|( $archive as xs:base64Binary|) as element(archive:entry)*}}<br /pre>
|- valign="top"
| '''Summary'''
* {{Code|compressed-size}}: compressed file size
An example:
<syntaxhighlight pre lang="xml">
<archive:entry size="1840" last-modified="2009-03-20T03:30:32" compressed-size="672">
doc/index.html
</archive:entry>
</syntaxhighlightpre>
|- valign="top"
| '''Errors'''
|'''Examples'''
|Sums up the file sizes of all entries of a JAR file:
<syntaxhighlight pre lang="'xquery"'>
sum(archive:entries(file:read-binary('zip.zip'))/@size)
</syntaxhighlightpre>
|}
{| width='100%'
|- valign="top"
| width='120' | '''SignaturesSignature'''|{{Func|<pre>archive:options|( $archive as xs:base64Binary|) as map(*)}}<br /pre>
|- valign="top"
| '''Summary'''
| '''Examples'''
|A standard ZIP archive will return the following options:
<syntaxhighlight pre lang="'xquery"'>
map {
"format": "zip",
"algorithm": "deflate"
}
</syntaxhighlightpre>
|}
{| width='100%'
|- valign="top"
| width='120' | '''SignaturesSignature'''|{{Func|archive:extract-text|$archive as xs:base64Binary|xs:string*}}<br/pre>{{Func|archive:extract-text|( $archive as xs:base64Binary, $entries as item()*|xs:string*}}<br/>{{Func|archive :extract-text|$archive as xs:base64Binary, $entries as item= ()*, $encoding as xs:string| := ()) as xs:string*}}<br/pre>
|- valign="top"
| '''Summary'''
|- valign="top"
| '''Errors'''
|{{Error|encode|#Errors}} the specified encoding is invalid or not supported, or the string conversion failed. Invalid XML characters will be ignored if {{Option|CHECKSTRINGS}} is turned off.<br />{{Error|error|#Errors}} archive creation failed.
|- valign="top"
| '''Examples'''
|The following expression extracts all {{Code|.txt}} files from an archive:
<syntaxhighlight pre lang="'xquery"'>
let $archive := file:read-binary("documents.zip")
for $entry in archive:entries($archive)[ends-with(., '.txt')]
return archive:extract-text($archive, $entry)
</syntaxhighlightpre>
|}
{| width='100%'
|- valign="top"
| width='120' | '''SignaturesSignature'''|{{Func|archive:extract-binary|$archive as xs:base64Binary|xs:base64Binary*}}<br/pre>{{Func|archive:extract-binary|( $archive as xs:base64Binary, $entries as item()*| := ()) as xs:base64Binary*}}</pre>
|- valign="top"
| '''Summary'''
| '''Examples'''
|This example unzips all files of an archive to the current directory:
<syntaxhighlight pre lang="'xquery"'>
let $archive := file:read-binary('archive.zip')
let $entries := archive:entries($archive)
file:create-dir(replace($entry, "[^/]+$", "")),
file:write-binary($entry, $content)
})</syntaxhighlightpre>
|}
{| width='100%'
|- valign="top"
| width='120' | '''SignaturesSignature''' |{{Func|archive:create|$entries as item(), $contents as item()*|xs:base64Binary}}<br /pre>{{Func|archive:create|( $entries as item(), $contents as item()*, $options as map(*)?| := map { }) as xs:base64Binary}}<br /pre>
|- valign="top"
| '''Summary'''
* {{Code|encoding}}: for textual entries (default: UTF-8)
An example:
<syntaxhighlight pre lang="xml">
<archive:entry last-modified='2011-11-11T11:11:11'
compression-level='8'
encoding='US-ASCII'>hello.txt</archive:entry>
</syntaxhighlightpre>
The actual {{Code|$contents}} must be {{Code|xs:string}} or {{Code|xs:base64Binary}} items.<br/>
The {{Code|$options}} parameter contains archiving options:
|- valign="top"
| '''Errors'''
|{{Error|number|#Errors}} the number of entries and contents differs.<br />{{Error|format|#Errors}} the specified option or its value is invalid or not supported.<br />{{Error|descriptor|#Errors}} entry descriptors contain invalid entry names, timestamps or compression levels.<br/>{{Error|encode|#Errors}} the specified encoding is invalid or not supported, or the string conversion failed. Invalid XML characters will be ignored if {{Option|CHECKSTRINGS}} is turned off.<br/>{{Error|single|#Errors}} the chosen archive format only allows single entries.<br />{{Error|error|#Errors}} archive creation failed.
|- valign="top"
| '''Examples'''
|The following one-liner creates an archive {{Code|archive.zip}} with one file {{Code|file.txt}}:
<syntaxhighlight pre lang="'xquery"'>
archive:create(<archive:entry>file.txt</archive:entry>, 'Hello World')
</syntaxhighlightpre>
The following function creates an archive {{Code|mp3.zip}}, which contains all MP3 files of a local directory:
<syntaxhighlight pre lang="'xquery"'>
let $path := 'audio/'
let $files := file:list($path, true(), '*.mp3')
return file:read-binary($path || $file)
)
return file:write-binary('mp3.zip', $zip)</syntaxhighlightpre>
|}
{| width='100%'
|- valign="top"
| width='120' | '''SignaturesSignature'''|{{Func|<pre>archive:update|( $archive as xs:base64Binary, $entries as item()*, $contents as item()*|) as xs:base64Binary}}</pre>
|- valign="top"
| '''Summary'''
|- valign="top"
| '''Errors'''
|{{Error|number|#Errors}} the number of entries and contents differs.<br />{{Error|descriptor|#Errors}} entry descriptors contain invalid entry names, timestamps, compression levels or encodings.<br/>{{Error|encode|#Errors}} the specified encoding is invalid or not supported, or the string conversion failed. Invalid XML characters will be ignored if {{Option|CHECKSTRINGS}} is turned off.<br />{{Error|modify|#Errors}} the entries of the given archive cannot be modified.<br/>{{Error|error|#Errors}} archive creation failed.
|- valign="top"
| '''Examples'''
|This example replaces texts in a Word document:
<syntaxhighlight pre lang="'xquery"'>
declare variable $input := "HelloWorld.docx";
declare variable $output := "HelloUniverse.docx";
let $updated := archive:update($archive, $doc, $entry)
return file:write-binary($output, $updated)
</syntaxhighlightpre>
|}
{| width='100%'
|- valign="top"
| width='120' | '''SignaturesSignature'''|{{Func|<pre>archive:delete|( $archive as xs:base64Binary, $entries as item()*|) as xs:base64Binary}}</pre>
|- valign="top"
| '''Summary'''
| '''Examples'''
|This example deletes all HTML files in an archive and creates a new file:
<syntaxhighlight pre lang="'xquery"'>
let $zip := file:read-binary('old.zip')
let $entries := archive:entries($zip)[matches(., '\.x?html?$', 'i')]
return file:write-binary('new.zip', archive:delete($zip, $entries))
</syntaxhighlightpre>
|}
{| width='100%'
|- valign="top"
| width='120' | '''SignaturesSignature'''|{{Func|archive:create-from|$path as xs:string|xs:base64Binary}}<br/pre>{{Func|archive:create-from|( $path as xs:string, $options as map(*)?|xs :base64Binary= map { }}<br/>{{Func|archive:create-from|$path as xs:string, $options as map(*)?, $entries as item()*| := ()) as xs:base64Binary}}</pre>
|- valign="top"
| '''Summary'''
|This convenience function creates an archive from all files in the specified directory {{Code|$path}}.<br/>The {{Code|$options}} parameter contains archiving options, and the files to be archived can be limited via {{Code|$entries}}. The format of the two last arguments is identical to {{Function||archive:create}}, but with two additional options are available:
* {{Code|recursive}}: parse all files recursively (default: {{Code|true}}; ignored if entries are specified via the last argument).
* {{Code|root-dir}}: use name of supplied directory as archive root directory (default: {{Code|false}}).
| '''Examples'''
|This example writes the files of a user’s home directory to <code>archive.zip</code>:
<syntaxhighlight pre lang="'xquery"'>
let $zip := archive:create-from('/home/user/')
return file:write-binary('archive.zip', $zip)
</syntaxhighlightpre>
|}
{| width='100%'
|- valign="top"
| width='120' | '''SignaturesSignature'''|{{Func|archive:extract-to|$path as xs:string, $archive as xs:base64Binary|empty-sequence()}}<br/pre>{{Func|archive:extract-to|( $path as xs:string, $archive as xs:base64Binary, $entries as item()*| := ()) as empty-sequence()}}</pre>
|- valign="top"
| '''Summary'''
| '''Examples'''
|The following expression unzips all files of an archive to the current directory:
<syntaxhighlight pre lang="'xquery"'>
archive:extract-to('.', file:read-binary('archive.zip'))
</syntaxhighlightpre>
|}
{| width='100%'
|- valign="top"
| width='120' | '''SignaturesSignature''' |{{Func|archive:write|$path as xs:string, $entries as item(), $contents as item()*|xs:base64Binary}}<br /pre>{{Func|archive:write|( $path as xs:string, $entries as item(), $contents as item()*, $options as map(*)?| := map { }) as xs:base64Binary}}<br /pre>
|- valign="top"
| '''Summary'''
|- valign="top"
| '''Errors'''
|{{Error|number|#Errors}} the number of entries and contents differs.<br />{{Error|format|#Errors}} the specified option or its value is invalid or not supported.<br />{{Error|descriptor|#Errors}} entry descriptors contain invalid entry names, timestamps or compression levels.<br/>{{Error|encode|#Errors}} the specified encoding is invalid or not supported, or the string conversion failed. Invalid XML characters will be ignored if {{Option|CHECKSTRINGS}} is turned off.<br/>{{Error|single|#Errors}} the chosen archive format only allows single entries.<br />{{Error|error|#Errors}} archive creation failed.
|- valign="top"
| '''Examples'''
|All mp3 files from a directory are zipped and written to a file, along with an info file:
<syntaxhighlight pre lang="'xquery"'>
let $files := file:children('music')[ends-with(., 'mp3')]
return archive:write(
('Archive with MP3 files', $files ! file:read-binary(.))
)
</syntaxhighlightpre>
|}
Bureaucrats, editor, reviewer, Administrators
13,554

edits

Navigation menu