The following function creates an archive {{Code|mp3.zip}}, which contains all MP3 files of a local directory:
<pre class="brush:xquery">
let $path := 'audio/'let $entries files := file:list($path, true(), '*.mp3')let $zip := zip2:create( for $f in $entries ! element files return <entry >{ . $f }</entry>, for $entries ! f in $files return file:read-binary($path || .$f)
)
return file:write-binary('mp3.zip', $zip)</pre>