Compress a collection to a zip folder
Posted: Mon Aug 11, 2014 9:24 pm
Hi guys,
I use eXist 2.2RC1 for this project.
I need to archive the contents of a collection (two .doc and a .vbs files) to a zip file using xQuery.
After some research, I found out about two functions that could help me out:
- compression:zip()
- response-stream-binary()
Now, the first function apparently enables us to zip either a set of entries or a collection to a zip file. I'm not sure if the second one is useful or not but since it enables us to specify the mimetype and the output name, I thought it might be.
The problem is that I can't seem to find how to indicate the target location of the output zip folder. As a result, the zip never gets created as a physical folder. I can display what seems to be the output stream using the response:stream binary() function but I actually have to store the zip file somewhere on the database.
This is what I've been doing so far:
Does any of you have an idea how to proceed, or maybe an alternative to this?
I use eXist 2.2RC1 for this project.
I need to archive the contents of a collection (two .doc and a .vbs files) to a zip file using xQuery.
After some research, I found out about two functions that could help me out:
- compression:zip()
- response-stream-binary()
Now, the first function apparently enables us to zip either a set of entries or a collection to a zip file. I'm not sure if the second one is useful or not but since it enables us to specify the mimetype and the output name, I thought it might be.
The problem is that I can't seem to find how to indicate the target location of the output zip folder. As a result, the zip never gets created as a physical folder. I can display what seems to be the output stream using the response:stream binary() function but I actually have to store the zip file somewhere on the database.
This is what I've been doing so far:
Code: Select all
let $collection := "/db/apps/sample" (: path to the collection I want to zip :)
return (
compression:zip(xs:anyURI($collection), true()), (: just using compression:zip :)
response:stream-binary(compression:zip(xs:anyURI($collection), true()), "application/zip", "test.zip")(: using response:stream-binary and compression:zip :)