InputSource

Denys Duchier

provides
x-ozlib://duchier/op/InputSource.ozf

Purpose

An InputSource is an object from which bytes can be read, i.e. just like Open.file in read mode. However the actual data can be obtained from a number of arbitrary sources like files, urls or virtual strings as if they had been lazily concatenated. For example: functor import InputSource at 'x-ozlib://duchier/op/InputSource.ozf' define ... F = {New InputSource.'class' init([file(FILE1) url(URL2) vs(VS3)])} ... end F will behave as if the data in file FILE1, in document at url URL2, and in virtual string VS3 had been lazily concatenated. This data can be read using the read method as in Open.file

Installation

This package can be installed by following the usual configure, build, install procedure, i.e. by executing a the shell: ./configure make install By default, all files of the package are installed in the user's ~/.oz directory tree. In particular, all modules are installed in the user's private cache.

API

You can check the automatically generated API produced by ozh. However in brief:

An input source object responds to the methods below

init(Specs)
where Specs is a list of specs. Each spec if either a file name or url, or more explicitly a record whose label indicates the type of source: files(S) files([S1 ... Sn]) url(S) urls([S1 ... Sn]) vs(S) string(S)

read(list:L tail:T<=nil size:S<=1024 len:N<=_)
same as in Open

get($)
reads and returns some more data. It returns nil only when the source is exhausted. It is equivalent to read(list:$)

close()
close the stream, release resources.

The module exports several classes for creating input sources

{New InputSource.'class' init(Specs)}
the basic way to create a new input source. Specs is a list of specs as described above.

{New InputSource.file init(File)}
{New InputSource.files init([File1 ... FileN])}
{New InputSource.url init(URL)}
{New InputSource.urls init([URL1 ... URLN])}
{New InputSource.vs init(VS)}
{New InputSource.string init(VS)}
for convenience, specialized classes are also provided for all the frequent cases.


Denys Duchier