Created
January 17, 2020 18:14
-
-
Save joewiz/7d591967fa7841a4c283cd6d741b9c22 to your computer and use it in GitHub Desktop.
Construct a zip file and stream it to a browser, with XQuery & eXist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xquery version "3.1"; | |
let $node := <root><x/></root> | |
let $entry := <entry name="test.xml" type="xml">{$node}</entry> | |
let $zip := compression:zip($entry, true()) | |
let $name := "test.zip" | |
return | |
response:stream-binary($zip, "media-type=application/zip", "test.zip") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xquery version "3.1"; | |
let $zip-filename := "test.zip" | |
let $contents := | |
array { | |
map { | |
"content": <root><x/></root>, | |
"filename": "test.xml", | |
"serialization": map { "indent": true() } | |
} | |
} | |
let $entries := | |
for $item in $contents?* | |
return | |
element entry { | |
attribute name { $item?filename }, | |
attribute type { | |
if (map:contains($item, "type")) then | |
$item?type | |
else (: if ($item instance of node()) then :) | |
"xml" | |
(: TODO add support for other types: collection|uri|binary|xml|text :) | |
}, | |
attribute method { | |
if (map:contains($item, "method")) then | |
$item?store | |
else | |
"store" | |
}, | |
if (map:contains($item, "serialization")) then | |
serialize($item?content, $item?serialization) | |
else | |
$item?content | |
} | |
let $binary-data := compression:zip($entries, true()) | |
return | |
response:stream-binary($binary-data, "media-type=application/zip", $zip-filename) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment