# Import from ZIP as specific format [duplicate]

This question already has an answer here:

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.

## marked as duplicate by Szabolcs, Community♦Dec 3 '16 at 11:46

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

• let me guess what you are just trying :-). Have you tried Import["a.foo", {"ZIP", "x.m", "HeldExpressions"}], that seems to work for me... It even is kind of documented in the details section of Import (in the part "assume also compression formats...") – Albert Retey Dec 3 '16 at 10:22
• @AlbertRetey Please post an answer ... I really couldn't find it – Szabolcs Dec 3 '16 at 10:35
• Related, perhaps duplicate?: mathematica.stackexchange.com/q/2871/121 – Mr.Wizard Dec 3 '16 at 10:43

## 1 Answer

The following seems to work:

 Import["a.foo", {"ZIP", "x.m", "HeldExpressions"}]


the documentation is not really clear about it, but the explanation about compressed formats in the Details section of the Import documentation page can be read as if this should work.