xdmp.zipCreate

xdmp.zipCreate(
   manifest as Array|Node,
   nodes as Array|Sequence
) as binary()

Summary

Create a zip file from a list of nodes.

Parameters
manifest The zip manifest should have the native JavaScript form:
  [
    {
      "lastModified": "2015-04-02T09:50:38",
      "path": "archive/friends.jpg"
    },
    {
      "path": "archive/notes.txt"
    }
  ]    
Any property other than path and lastModified are ignored. If the lastModified property is specified, that date and time will be set for the part. Otherwise, if the node for the part comes from a database that tracks the last modified time of a document, that date and time will be used. The current date and time will be used if no other value is available. Due to a limitation in the zip file format, the time has a granularity of two seconds (e.g. 10:22:33 becomes 10:22:32). The element form is accepted but deprecated.
nodes The nodes that you want to zip up. The nodes correspond to the objects in the manifest (named 'part' in the XQuery version), where the first node corresponds to the first part object specified, the second node to the second part object, and so on. Specifying a different number of part objects than nodes will result in an error.

Usage Notes

While you can create a zip file of encrypted content, xdmp.zipCreate does not have the capability to encrypt the content to be zipped.

The 'part' objects in the manifest should contain relative paths so the zip file can be unpacked into its own directory; do not start the path with a forward slash or a backslash.

To support creating Open Container Format archives for the EPUB format, xdmp.zipCreate will not compress the first part if it is named "mimetype".

Example

const zip = xdmp.zipCreate(
                [{ 'path': '/mydoc.xml' },
                 { 'lastModified': '2018-10-02T09:50:00',
                   'path': '/mypicture.jpg' }
                ],
                [cts.doc('/mydoc.xml'), cts.doc('/mypicture.jpg')]);
xdmp.save('/tmp/myzip.zip', zip);

// Creates a zip archive that includes the documents "/mydoc.xml"
// and "/mypicture.jpg", then saves that to the filesystem.

Example

//  the "mimetype" file will not be compressed, so as to support
//  the EPUB format 

var nb = new NodeBuilder();
const mimedoc = nb.startDocument()
                    .addText('application/epub+zip')
                  .endDocument()
                  .toNode();

const zip = xdmp.zipCreate(
            [{path:'mimetype'},
             {path:'META-INF/container.xml'},
             {path:'OEBPS/content.opf'},
             {path:'OEBPS/content.pdf'}
            ],
            [mimedoc,
             cts.doc('/my-doc/container.xml'),
             cts.doc('/my-doc/content.opf'),
             cts.doc('/my-doc/content.pdf')
             ]);
xdmp.save('/tmp/mydoc.epub', zip);

// Creates a zip archive that meets the OCF specification,
// then saves that to the filesystem.

Powered by MarkLogic Server | Terms of Use | Privacy Policy