[erlang-questions] Read from a compressed "GZIP" file

zabrane Mikael zabrane3@REDACTED
Fri Nov 27 18:38:34 CET 2009


Thanks very much Vinayak!
Exactly what I needed

2009/11/27 Vinayak Pawar <vinayakapawar@REDACTED>

>
> Z = zlib:open(),
> zlib:inflateInit(Z, 31),
>
> % hopefully everything fits in memory
> % if file size is big, you can do this read and inflate in chunks
>
> CompressedBin = file:read_file(Filename),
>
> Uncompressed = zlib:inflate(Z, CompressedBin),
>
> zlib:inflateEnd(Z),
> zlib:close(Z).
>
> Hope this helps!
>
> Thanks,
> Vinayak
>
>
> On Fri, Nov 27, 2009 at 7:41 PM, zabrane Mikael <zabrane3@REDACTED>wrote:
>
>> Hi List,
>>
>> Is there a way to read from a GZIPped file (example please)?
>> I found a mode called "compressed" in the "file" module, but failed to
>> understand how it works:
>>
>> $ erl
>> 1> {ok, FH} = file:open("foo.gz", [read, compressed]).
>> {ok,<0.42.0>}
>>
>> 2> {ok, Bin} = file:read(FH, 8).
>> ** exception error: no match of right hand side value {error,terminated}
>>
>> Why am I faling to read 8 bytes from it?
>> How can I read the whole file in one go?
>>
>> Regards
>> Zabrane
>>
>
>


More information about the erlang-questions mailing list