My zip file has files nested in subfolders. First I used db:store to store delta.zip into the database. My first problem was I got an error " *invalid entry CRC: expected 0x0 but got..."* The raw stored file was slightly larger *than the original zip.* So I replaced the zip file in the raw folder with the original one and the first error went away. Now I don't get any error bu the extracted file are not stored as binaries
What is wrong with this code? I removed the updating annotation and returned $target instead of the try/store/catch inside the loop and got the expected result path name
let $database := 'db' let $extractTo := 'target.zip'
(: path to raw stored zip :) let $archivePath := 'alpha/bravo/charlie/delta.zip'
let $archive := db:retrieve($database, $archivePath) let $basePath := replace($archivePath, '[^/]+$', '') || $extractTo let $entries := archive:entries($archive) let $contents := archive:extract-binary($archive) return for-each-pair($entries, $contents, %updating function($entry, $content) { let $target := $basePath || '/' || $entry/text() return try { db:store($database, $target, $content) } catch * { () } })
First I used db:store to store delta.zip into the database. My first problem was I got an error "invalid entry CRC: expected 0x0 but got..." The raw stored file was slightly larger than the original zip.
Could you possibly give us an example to reproduce this?
What is wrong with this code?
The info view shows…
Result: - Hit(s): 0 Items - Updated: 0 Items - Printed: 0 Bytes - Read Locking: global - Write Locking: none
…so my current assumption is that the higher-order functions are not prepared yet to do updates. I will look at this. For now, the following code should work.
for $entry at $pos in $entries let $content := $contents[$pos] let $target := $basePath || '/' || $entry/text() return db:store($database, $target, $content)
Notice, btw, that try/catch won’t catch anything in your query, because the update itself will be run after query evaluation has been completed (look for Pending Update List in our documentation for more information).
return for-each-pair($entries, $contents, %updating function($entry,
In the latest snapshot [1], the built-in higher-order functions (for-each-pair, apply, etc.) are not allowed anymore to evaluate updating functions. As a result, your original query will now yield an error (XPTY0004). As I didn’t see this covered in the specs, I have added a W3 bug entry [2].
Cheers, Christian
[1] http://files.basex.org/releases/latest/ [2] https://www.w3.org/Bugs/Public/show_bug.cgi?id=29333
$content) { let $target := $basePath || '/' || $entry/text() return try { db:store($database, $target, $content) } catch * { () } })
basex-talk@mailman.uni-konstanz.de