I have a ZIP archive that does not have the .zip
file extension. How can I import a file from this archive using Import
and specifying a particular import format or element?
Test case:
SetDirectory@CreateDirectory[]
x = 1;
Export["x.m", HoldComplete[x], "HeldExpressions"]
CreateArchive["x.m"]
RenameFile["x.m.zip", "a.foo"]
Now I can
Import["a.foo", {"ZIP", "x.m"}]
(* 1 *)
But I want to import x.m
as "HeldExpressions"
. How can I do this? I cannot figure out the syntax.
Doing this is useful because lots of file formats are based on zip, e.g. Java JAR files, Microsoft Office files, .paclet
files, etc. Suppose I want to import an XML from a .docx
or I want to import a PacletInfo.m
as "HeldExpressions"
.
I know I can ExtractArchive
first, import, and delete the extracted file. This question is about whether this is achievable with a single Import
call.
Import["a.foo", {"ZIP", "x.m", "HeldExpressions"}]
, that seems to work for me... It even is kind of documented in the details section ofImport
(in the part "assume also compression formats...") $\endgroup$