Using Zlib

Vladimir Sekissov svg@REDACTED
Wed Jun 19 19:30:22 CEST 2002


willem> Vladimir Sekissov wrote:
willem> > I've looked around the code and it seemed they could use compressed files with
willem> > `compressed' flag.
willem> 
willem> Thanks, that's interesting!
willem> 
willem> However, I was hoping it could be used to uncompress an incoming TCP data 
willem> stream. I guess that's out of reach... :-(

You can use ram_file, I think:

74> {ok, FD} = file:open("TestTest", [read, write, ram]).
{ok,{file_descriptor,ram_file,#Port<0.68>}}

75> ram_file:get_size(FD).
{ok,8}

76> ram_file:position(FD, 0).
{ok,0}

77> ram_file:read(FD, 8).
{ok,"TestTest"}

78> ram_file:compress(FD).
{ok,26}

79> ram_file:read(FD, 26).
{ok,[31,139,8,0,0,0,0,0,0,3,11,73,45,46,9,1,98,0,89,118,45,181,8,0,0,0]}

80> ram_file:uncompress(FD).
{ok,8}

81> ram_file:read(FD, 8).
{ok,"TestTest"}

83> ram_file:close(FD).
ok

See code of ram_file.erl for interface.

Best Regards,

Vladimir Sekissov



More information about the erlang-questions mailing list