AmendHub

Download:

jcs

/

subtext

/

amendments

/

358

zip: Add zip_is_zip_file


jcs made amendment 358 about 1 year ago
--- zip.c Tue Feb 28 17:45:24 2023 +++ zip.c Thu Mar 2 21:46:59 2023 @@ -52,6 +52,30 @@ zip_read(short frefnum, void *buf, size_t len) } bool +zip_is_zip_file(Str255 path) +{ + char buf[32]; + short error, frefnum; + bool ret = false; + + error = FSOpen(path, 0, &frefnum); + if (error) { + warn("failed opening %s: %d", PtoCstr(path), error); + CtoPstr(path); + return false; + } + + if (zip_read(frefnum, &buf, 4) == 4 && + memcmp(buf, &zip_file_magic, 4) == 0) + ret = true; + +read_done: + FSClose(frefnum); + return ret; + +} + +bool zip_read_file(Str255 path, zip_extract_decider *decider, zip_extract_processor *processor) { @@ -203,7 +227,7 @@ zip_read_file(Str255 path, zip_extract_decider *decide } free(comp); - processor(filename, uncomp_len, uncomp); + processor(filename, uncomp, uncomp_len); free(uncomp); } else { /* skip over it */ --- zip.h Tue Feb 28 17:45:24 2023 +++ zip.h Thu Mar 2 21:46:43 2023 @@ -31,8 +31,9 @@ typedef bool zip_extract_decider(char *filename, size_t extracted_size); typedef void zip_extract_processor(char *filename, - size_t extracted_size, unsigned char *extracted_data); + unsigned char *extracted_data, size_t extracted_size); +bool zip_is_zip_file(Str255 path); bool zip_read_file(Str255 path, zip_extract_decider *decider, zip_extract_processor *processor);