-1
$\begingroup$

How do I import a text file that is compressed inside a .Zip file using OpenRead? I know how to do it using Import

pathArqANL = "file_xyz.zip";
Import[pathArqANL, {FileBaseName[pathArqANL] <> ".anl", "Table"}]

I tried something like this:

OpenRead[pathArqANL, Method -> {"File"}]

But I found no documentation about Method.

$\endgroup$
  • 1
    $\begingroup$ Why do you need to use OpenRead instead of Import? I'm not sure your way will work in all OS. $\endgroup$ – rhermans Jul 26 '18 at 20:08
  • $\begingroup$ My file is about 1 GB or more. With "Import" it takes a long time, furthermore I have to filter some text inside file to get only numbers. By the way, compression rate 1 1/5, that is, files of 1 GB are stored as Zip with 200 MB. $\endgroup$ – LeoRon7 Jul 26 '18 at 20:16
  • $\begingroup$ Small hack OpenRead[File["!unzip -p file_xyz.zip"]] $\endgroup$ – swish Jul 26 '18 at 20:20
  • $\begingroup$ @swish That does not work on Windows. $\endgroup$ – rhermans Jul 26 '18 at 22:28
  • $\begingroup$ @LeoRon7 is there a single compressed file in each zip file? Would it be a problem to unzip the file before reading it? What system are you using? $\endgroup$ – rhermans Jul 26 '18 at 22:32
0
$\begingroup$

If you wish to stream the data, you could try something like

strm = StringToStream[Import[pathArqANL, {FileBaseName[pathArqANL] <> ".anl", "String"}]]

so that you can use ReadList etc which might be faster than Table Import if you already know the structure of the types of data in the file

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.