|
|
Section Intro: Stream Operators
Stream OperatorsSynopsis:A stream is a data object upon which various input and output operations may be performed. Meta-HTML provides commands for creating, opening, reading from, and writing to, stream objects. The referenced underlying object may either be a file or a network connection. Commands:
More Information:
There are three special
names which can be used with
Reads a chunk of data from STREAM and returns it. STREAM is read until the character value specified by CHARACTER (defaulting to a newline) is reached, and that data upto and including the final CHARACTER is returned. One way to read all of the available data is to supply the empty string as the value of STOP-AT:
<with-open-stream stream www.ua.com:80 type=tcp mode=read-write> <stream-put stream "GET /welcome.mhtml HTTP/1.0\n\n"> <set-var the-page = <stream-get stream stop-at="">> </with-open-stream>
Reads the contents of the stream STREAM into the binary
variable VAR. You can easily use this in conjunction with
If STOP-AT is supplied, it is a character at which the function
should stop reading data from the stream. Unlike
If CHUNK-SIZE is supplied, it is the amount to read at one time. This is useful for when you have an unbounded amount of data to read, and you would like to process it in manageable chunks. For example, the following code copies data from an open network stream to a file on the local disk, without using more than 32k of memory:
<with-open-stream src data-server.ua.com:2345 type=tcp mode=read>
<with-open-stream dst /tmp/datafile type=file mode=write-create>
<while <stream-readable s>>
<stream-get-contents src chunk chunk-size=32768>
<stream-put-contents dst chunk>
</while>
</with-open-stream>
</with-open-stream>
Return an association list providing information about STREAM.
Writes STRING to the open STREAM.
Writes the contents of the variable VAR to the open STREAM. This is the only way to get the contents of a binary variable
written to a stream. Binary variables are generally created with
Returns "true" if STREAM is an open stream which was opened with a mode of read, or read-write, and which still has data pending.
The optional keyword DELAY is used to specify the amount of time
in seconds that
Only for use with network streams, this tells the underlying operating system (and the other end of the network connection) that no additional input or output will be done using this object. In effect, it immediately closes the stream.
When used in conjunction with a network stream opened on
Returns "true" if STREAM is an open stream which was opened with a mode of write, append, read-write, or write-create, and which is available to have data written to it.
The optional keyword DELAY is used to specify the amount of time
in seconds that
Create an environment in which VAR is bound to the indicator of an open stream, named by NAME.
The stream is either of type
When TYPE is
When TYPE is Finally, the keyword argument NOTIMEOUT=TRUE may be given, which indicates that the amount of time that Meta-HTML should wait during IO operations on this stream is infinite -- all processing will block until the stream is successfully read from or written to. The default timeout is dependent on which specific operation is being performed, and the amount of data which is being read or written, but is generally suitable for writing data at about 14.4kbps. The possible values for MODE are:
When one is opening, reading to, or writing from a network stream, the amount of time it can take to finish the operation is indeterminate. So, the keyword argument TIMEOUT=VALUE can be used to specify the maximum amount of time (in seconds) that these operations may take. If the value is specified as "never", then these operations can take "forever". If the value isn't specified, then the operations calculate the maximum wait time dynamically, based upon the amount of information to be read or written. Any other value specifies an absolute maximum number of seconds.
Edit Section
![]() The META-HTML Reference Manual V2.0 Copyright © 1995, 1998, Brian J. Fox Found a bug? Send mail to bug-manual@metahtml.org |