Changes

Jump to navigation Jump to search
132 bytes removed ,  18:31, 1 December 2023
m
Text replacement - "<syntaxhighlight lang="xquery">" to "<pre lang='xquery'>"
|'''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)
</syntaxhighlight>
| '''Examples'''
|A standard ZIP archive will return the following options:
<syntaxhighlight pre lang="'xquery"'>
map {
"format": "zip",
| '''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')]
| '''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)
| '''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')
</syntaxhighlight>
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')
| '''Examples'''
|This example replaces texts in a Word document:
<syntaxhighlight pre lang="'xquery"'>
declare variable $input := "HelloWorld.docx";
declare variable $output := "HelloUniverse.docx";
| '''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')]
| '''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)
| '''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'))
</syntaxhighlight>
| '''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(
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu