aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/sisudoc/ocda/io_in/read_zip_pod.d
diff options
context:
space:
mode:
Diffstat (limited to 'src/sisudoc/ocda/io_in/read_zip_pod.d')
-rw-r--r--src/sisudoc/ocda/io_in/read_zip_pod.d26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/sisudoc/ocda/io_in/read_zip_pod.d b/src/sisudoc/ocda/io_in/read_zip_pod.d
index 49429be..d0eb65a 100644
--- a/src/sisudoc/ocda/io_in/read_zip_pod.d
+++ b/src/sisudoc/ocda/io_in/read_zip_pod.d
@@ -63,6 +63,7 @@ template spineExtractZipPod() {
import std.regex;
import std.stdio;
import std.string : indexOf;
+ import sisudoc.ocda.zstd;
/+ security limits for zip extraction +/
enum size_t MAX_ENTRY_SIZE = 50 * 1024 * 1024; /+ 50 MB per entry +/
@@ -122,10 +123,29 @@ template spineExtractZipPod() {
}
/+ ↓ derive pod name from zip filename +/
string zip_basename = zip_path.baseName.stripExtension;
- /+ ↓ read and parse zip archive +/
+ /+ ↓ read and parse the pod archive.
+ a .sisupod is one zstd frame wrapping the archive spine writes, so
+ the bytes are unwrapped before the archive is parsed. Determined from
+ the first four bytes and not from the filename: a pod published as a
+ plain .zip, or one a reader has renamed, is read either way. Everything
+ after this point sees the same archive it always did, guards included.
+ +/
+ ubyte[] _archive_bytes;
+ try {
+ _archive_bytes = cast(ubyte[]) read(zip_path);
+ if (zstdIsFrame(_archive_bytes)) {
+ _archive_bytes = zstdDecompress(_archive_bytes, MAX_TOTAL_SIZE);
+ }
+ } catch (ZstdException ex) {
+ result.error_msg = "failed to decompress pod archive: " ~ zip_path ~ " - " ~ ex.msg;
+ return result;
+ } catch (Exception ex) {
+ result.error_msg = "error reading pod archive: " ~ zip_path ~ " - " ~ ex.msg;
+ return result;
+ }
ZipArchive zip;
try {
- zip = new ZipArchive(read(zip_path));
+ zip = new ZipArchive(_archive_bytes);
} catch (ZipException ex) {
result.error_msg = "failed to read zip archive: " ~ zip_path ~ " - " ~ ex.msg;
return result;
@@ -274,7 +294,7 @@ template spineExtractZipPod() {
its own, carrying its images. A .ssp is not here: it describes its
images without carrying them, so it would arrive without them.
+/
- static auto rgx_url_source = ctRegex!(`^https?://[a-zA-Z0-9._:/-]+([.]zip|[.]ocda[.]db)$`);
+ static auto rgx_url_source = ctRegex!(`^https?://[a-zA-Z0-9._:/-]+([.]sisupod|[.]zip|[.]ocda[.]db)$`);
struct DownloadResult {
string local_path; /+ path to downloaded temp file +/