lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


"Tiago Dionizio" <tiago.dionizio@gmail.com> wrote:
> I have been thinking - and doing some work - about adapting the zlib
> binding to be able to support zlib streams using a file like
> interface.

While I can't comment on your actual proposal re zlib (I am using a
different library for that purpose) I'd like make a general remark which
may or may not be of interest in this context.

There are many occasions where a stream-based interface is (or could be)
used. Disk-based files (basically the functions in module io) are simply
a sort of standard case. Archive support, as outlined by you, is
another; memory-based files are yet another.

Wouldn't it be nice if the io module were layered and accepted, within
the functional framework already defined, "drivers" which implement the
actual I/O? These pluggable drivers would use the infrastructure of the
io module, both internally (ie code in liolib.c) and externally. File
access via the C runtime (as already implemented in io) would be
included by default but this would just be one of many possible drivers
which can use the io framework.

Installed stream drivers could be activated by calling io.open() with a
special first parameter. The exact semantics are of course debatable. Eg
as a string:

f=io.open("test.txt") opens a disk-based file, as usual.
f=io.open("memory:test") opens a memory-based file called test.
f=io.open("zip:test.zip:test.txt") opens a file in file test.zip

-- 
cheers  thomasl

web: http://thomaslauer.com/start