I have written an XQuery that properly extracts binary(raw) archive resource contents to binary(raw) resources. However since archive:extract:-binary returns the contents as xs:base64Binary and not streamable items, large archive contents are loaded completely into memory and will often cause an OutOfMemoryException. I have increased the BaseX JVM heap size and the problem goes away, but this is not acceptable in a system where many users may be doing this concurrently. archive:extract-to seems to only extract to an external file-system location and not to binary(raw) resources. Example code is provided below that extracts to the same database folder as the archive, however the target location of the contents is not pertinent to the problem.
let $database := 'db' let $archivePath := 'myfolder/myarchive.zip' let $archive := db:retrieve($database, $archivePath) let $basePath := replace($archivePath, '[^/]+$', '') let $entries := archive:entries($archive) let $contents := archive:extract-binary($archive) for $entry at $pos in $entries let $content := $contents[$pos] let $target := $basePath || '/' || $entry/text() return db:store($database, $target, $content)