This commit is contained in:
Robby Findler 2011-02-08 22:21:05 -06:00
parent 16d96cf91e
commit 9f18589c4f

View File

@ -14,8 +14,8 @@
@defproc[(port->list [r (input-port? . -> . any/c) read] [in input-port? (current-input-port)]) @defproc[(port->list [r (input-port? . -> . any/c) read] [in input-port? (current-input-port)])
(listof any/c)]{ (listof any/c)]{
Returns a list whose elements are produced by calling @scheme[r] Returns a list whose elements are produced by calling @racket[r]
on @scheme[in] until it produces @scheme[eof]. on @racket[in] until it produces @racket[eof].
@examples[#:eval port-eval @examples[#:eval port-eval
(define (read-number input-port) (define (read-number input-port)
@ -28,14 +28,14 @@ on @scheme[in] until it produces @scheme[eof].
@defproc[(port->string [in input-port? (current-input-port)]) string?]{ @defproc[(port->string [in input-port? (current-input-port)]) string?]{
Reads all characters from @scheme[in] and returns them as a string. Reads all characters from @racket[in] and returns them as a string.
@examples[#:eval port-eval @examples[#:eval port-eval
(port->string (open-input-string "hello world")) (port->string (open-input-string "hello world"))
]} ]}
@defproc[(port->bytes [in input-port? (current-input-port)]) bytes?]{ @defproc[(port->bytes [in input-port? (current-input-port)]) bytes?]{
Reads all bytes from @scheme[in] and returns them as a @tech{byte string}. Reads all bytes from @racket[in] and returns them as a @tech{byte string}.
@examples[#:eval port-eval @examples[#:eval port-eval
(port->bytes (open-input-string "hello world")) (port->bytes (open-input-string "hello world"))
@ -45,10 +45,10 @@ Reads all bytes from @scheme[in] and returns them as a @tech{byte string}.
[#:line-mode line-mode (or/c 'linefeed 'return 'return-linefeed 'any 'any-one) 'any]) [#:line-mode line-mode (or/c 'linefeed 'return 'return-linefeed 'any 'any-one) 'any])
(listof string?)]{ (listof string?)]{
Read all characters from @scheme[in], breaking them into lines. The Read all characters from @racket[in], breaking them into lines. The
@scheme[line-mode] argument is the same as the second argument to @racket[line-mode] argument is the same as the second argument to
@scheme[read-line], but the default is @scheme['any] instead of @racket[read-line], but the default is @racket['any] instead of
@scheme['linefeed]. @racket['linefeed].
@examples[#:eval port-eval @examples[#:eval port-eval
(port->lines (port->lines
@ -59,8 +59,8 @@ Read all characters from @scheme[in], breaking them into lines. The
[#:line-mode line-mode (or/c 'linefeed 'return 'return-linefeed 'any 'any-one) 'any]) [#:line-mode line-mode (or/c 'linefeed 'return 'return-linefeed 'any 'any-one) 'any])
(listof bytes?)]{ (listof bytes?)]{
Like @scheme[port->lines], but reading bytes and collecting them into Like @racket[port->lines], but reading bytes and collecting them into
lines like @scheme[read-bytes-line]. lines like @racket[read-bytes-line].
@examples[#:eval port-eval @examples[#:eval port-eval
(port->bytes-lines (port->bytes-lines
@ -72,35 +72,35 @@ lines like @scheme[read-bytes-line].
[#:separator separator any/c #"\n"]) [#:separator separator any/c #"\n"])
void?]{ void?]{
Use @scheme[display] to each each element of @scheme[lst] to @scheme[out], adding Use @racket[display] to each each element of @racket[lst] to @racket[out], adding
@scheme[separator] after each element.} @racket[separator] after each element.}
@defproc[(call-with-output-string [proc (output-port? . -> . any)]) string?]{ @defproc[(call-with-output-string [proc (output-port? . -> . any)]) string?]{
Calls @scheme[proc] with an output port that accumulates all output Calls @racket[proc] with an output port that accumulates all output
into a string, and returns the string. into a string, and returns the string.
The port passed to @scheme[proc] is like the one created by The port passed to @racket[proc] is like the one created by
@scheme[open-output-string], except that it is wrapped via @racket[open-output-string], except that it is wrapped via
@scheme[dup-output-port], so that @scheme[proc] cannot access the @racket[dup-output-port], so that @racket[proc] cannot access the
port's content using @scheme[get-output-string]. If control jumps back port's content using @racket[get-output-string]. If control jumps back
into @scheme[proc], the port continues to accumulate new data, and into @racket[proc], the port continues to accumulate new data, and
@scheme[call-with-output-string] returns both the old data and newly @racket[call-with-output-string] returns both the old data and newly
accumulated data.} accumulated data.}
@defproc[(call-with-output-bytes [proc (output-port? . -> . any)]) bytes?]{ @defproc[(call-with-output-bytes [proc (output-port? . -> . any)]) bytes?]{
Like @scheme[call-with-output-string], but returns accumulated results Like @racket[call-with-output-string], but returns accumulated results
in a @tech{byte string} instead of a string. Furthermore, the port's in a @tech{byte string} instead of a string. Furthermore, the port's
content is emptied when @scheme[call-with-output-bytes] returns, so content is emptied when @racket[call-with-output-bytes] returns, so
that if control jumps back into @scheme[proc] and returns a second that if control jumps back into @racket[proc] and returns a second
time, only the newly accumulated bytes are returned.} time, only the newly accumulated bytes are returned.}
@defproc[(with-output-to-string [proc (-> any)]) string?]{ @defproc[(with-output-to-string [proc (-> any)]) string?]{
Equivalent to Equivalent to
@schemeblock[(call-with-output-string @racketblock[(call-with-output-string
(lambda (p) (parameterize ([current-output-port p]) (lambda (p) (parameterize ([current-output-port p])
(proc))))]} (proc))))]}
@ -108,30 +108,30 @@ Equivalent to
Equivalent to Equivalent to
@schemeblock[(call-with-output-bytes @racketblock[(call-with-output-bytes
(lambda (p) (parameterize ([current-output-port p]) (lambda (p) (parameterize ([current-output-port p])
(proc))))]} (proc))))]}
@defproc[(call-with-input-string [str string?] [proc (input-port? . -> . any)]) any]{ @defproc[(call-with-input-string [str string?] [proc (input-port? . -> . any)]) any]{
Equivalent to @scheme[(proc (open-input-string str))].} Equivalent to @racket[(proc (open-input-string str))].}
@defproc[(call-with-input-bytes [bstr bytes?] [proc (input-port? . -> . any)]) any]{ @defproc[(call-with-input-bytes [bstr bytes?] [proc (input-port? . -> . any)]) any]{
Equivalent to @scheme[(proc (open-input-bytes bstr))].} Equivalent to @racket[(proc (open-input-bytes bstr))].}
@defproc[(with-input-from-string [str string?] [proc (-> any)]) any]{ @defproc[(with-input-from-string [str string?] [proc (-> any)]) any]{
Equivalent to Equivalent to
@schemeblock[(parameterize ([current-input-port (open-input-string str)]) @racketblock[(parameterize ([current-input-port (open-input-string str)])
(proc))]} (proc))]}
@defproc[(with-input-from-bytes [bstr bytes?] [proc (-> any)]) any]{ @defproc[(with-input-from-bytes [bstr bytes?] [proc (-> any)]) any]{
Equivalent to Equivalent to
@schemeblock[(parameterize ([current-input-port (open-input-bytes str)]) @racketblock[(parameterize ([current-input-port (open-input-bytes str)])
(proc))]} (proc))]}
@ -143,13 +143,13 @@ Equivalent to
Takes any number of input ports and returns an input port. Reading Takes any number of input ports and returns an input port. Reading
from the input port draws bytes (and special non-byte values) from the from the input port draws bytes (and special non-byte values) from the
given input ports in order. If @scheme[close-at-eof?] is true, then given input ports in order. If @racket[close-at-eof?] is true, then
each port is closed when an end-of-file is encountered from the port, each port is closed when an end-of-file is encountered from the port,
or when the result input port is closed. Otherwise, data not read from or when the result input port is closed. Otherwise, data not read from
the returned input port remains available for reading in its original the returned input port remains available for reading in its original
input port. input port.
See also @scheme[merge-input], which interleaves data from multiple See also @racket[merge-input], which interleaves data from multiple
input ports as it becomes available.} input ports as it becomes available.}
@ -196,39 +196,39 @@ input ports as it becomes available.}
#f]) #f])
input-port?]{ input-port?]{
Similar to @scheme[make-input-port], but if the given @scheme[read-in] Similar to @racket[make-input-port], but if the given @racket[read-in]
returns an event, the event's value must be @scheme[0]. The resulting returns an event, the event's value must be @racket[0]. The resulting
port's peek operation is implemented automatically (in terms of port's peek operation is implemented automatically (in terms of
@scheme[read-in]) in a way that can handle special non-byte @racket[read-in]) in a way that can handle special non-byte
values. The progress-event and commit operations are also implemented values. The progress-event and commit operations are also implemented
automatically. The resulting port is thread-safe, but not kill-safe automatically. The resulting port is thread-safe, but not kill-safe
(i.e., if a thread is terminated or suspended while using the port, (i.e., if a thread is terminated or suspended while using the port,
the port may become damaged). the port may become damaged).
The @scheme[read-in], @scheme[close], @scheme[get-location], The @racket[read-in], @racket[close], @racket[get-location],
@scheme[count-lines!], @scheme[init-position], and @racket[count-lines!], @racket[init-position], and
@scheme[buffer-mode] procedures are the same as for @racket[buffer-mode] procedures are the same as for
@scheme[make-input-port]. @racket[make-input-port].
The @scheme[fast-peek] argument can be either @scheme[#f] or a The @racket[fast-peek] argument can be either @racket[#f] or a
procedure of three arguments: a byte string to receive a peek, a skip procedure of three arguments: a byte string to receive a peek, a skip
count, and a procedure of two arguments. The @scheme[fast-peek] count, and a procedure of two arguments. The @racket[fast-peek]
procedure can either implement the requested peek, or it can dispatch procedure can either implement the requested peek, or it can dispatch
to its third argument to implement the peek. The @scheme[fast-peek] is to its third argument to implement the peek. The @racket[fast-peek] is
not used when a peek request has an associated progress event. not used when a peek request has an associated progress event.
The @scheme[buffering?] argument determines whether @scheme[read-in] The @racket[buffering?] argument determines whether @racket[read-in]
can be called to read more characters than are immediately demanded by can be called to read more characters than are immediately demanded by
the user of the new port. If @scheme[buffer-mode] is not @scheme[#f], the user of the new port. If @racket[buffer-mode] is not @racket[#f],
then @scheme[buffering?] determines the initial buffer mode, and then @racket[buffering?] determines the initial buffer mode, and
@scheme[buffering?] is enabled after a buffering change only if the @racket[buffering?] is enabled after a buffering change only if the
new mode is @scheme['block]. new mode is @racket['block].
If @scheme[on-consumed] is not @scheme[#f], it is called when data is If @racket[on-consumed] is not @racket[#f], it is called when data is
read from the port, as opposed to merely peeked. The argument to read from the port, as opposed to merely peeked. The argument to
@scheme[on-consumed] is the result value of the port's reading @racket[on-consumed] is the result value of the port's reading
procedure, so it can be an integer or any result from procedure, so it can be an integer or any result from
@scheme[read-in].} @racket[read-in].}
@defproc[(make-limited-input-port [in input-port?] @defproc[(make-limited-input-port [in input-port?]
@ -236,17 +236,17 @@ procedure, so it can be an integer or any result from
[close-orig? any/c #t]) [close-orig? any/c #t])
input-port?]{ input-port?]{
Returns a port whose content is drawn from @scheme[in], but where an Returns a port whose content is drawn from @racket[in], but where an
end-of-file is reported after @scheme[limit] bytes (and non-byte end-of-file is reported after @racket[limit] bytes (and non-byte
special values) are read. If @scheme[close-orig?] is true, then the special values) are read. If @racket[close-orig?] is true, then the
original port is closed if the returned port is closed. original port is closed if the returned port is closed.
Bytes are consumed from @scheme[in] only when they are consumed from Bytes are consumed from @racket[in] only when they are consumed from
the returned port. In particular, peeking into the returned port peeks the returned port. In particular, peeking into the returned port peeks
into the original port. into the original port.
If @scheme[in] is used directly while the resulting port is also used, If @racket[in] is used directly while the resulting port is also used,
then the @scheme[limit] bytes provided by the port need not be then the @racket[limit] bytes provided by the port need not be
contiguous parts of the original port's stream.} contiguous parts of the original port's stream.}
@ -257,17 +257,17 @@ contiguous parts of the original port's stream.}
(values input-port? output-port?)]{ (values input-port? output-port?)]{
Returns two ports: an input port and an output port. The ports behave Returns two ports: an input port and an output port. The ports behave
like those returned by @scheme[make-pipe], except that the ports like those returned by @racket[make-pipe], except that the ports
support non-byte values written with procedures such as support non-byte values written with procedures such as
@scheme[write-special] and read with procedures such as @racket[write-special] and read with procedures such as
@scheme[get-byte-or-special]. @racket[get-byte-or-special].
The @scheme[limit] argument determines the maximum capacity of the The @racket[limit] argument determines the maximum capacity of the
pipe in bytes, but this limit is disabled if special values are pipe in bytes, but this limit is disabled if special values are
written to the pipe before @scheme[limit] is reached. The limit is written to the pipe before @racket[limit] is reached. The limit is
re-enabled after the special value is read from the pipe. re-enabled after the special value is read from the pipe.
The optional @scheme[in-name] and @scheme[out-name] arguments The optional @racket[in-name] and @racket[out-name] arguments
determine the names of the result ports.} determine the names of the result ports.}
@ -285,15 +285,15 @@ new port. After an end-of-file has been read from both original ports,
the new port returns end-of-file. Closing the merged port does not the new port returns end-of-file. Closing the merged port does not
close the original ports. close the original ports.
The optional @scheme[buffer-limit] argument limits the number of bytes The optional @racket[buffer-limit] argument limits the number of bytes
to be buffered from @scheme[a-in] and @scheme[b-in], so that the merge to be buffered from @racket[a-in] and @racket[b-in], so that the merge
process does not advance arbitrarily beyond the rate of consumption of process does not advance arbitrarily beyond the rate of consumption of
the merged data. A @scheme[#f] value disables the limit. As for the merged data. A @racket[#f] value disables the limit. As for
@scheme[make-pipe-with-specials], @scheme[buffer-limit] does not apply @racket[make-pipe-with-specials], @racket[buffer-limit] does not apply
when a special value is produced by one of the input ports before the when a special value is produced by one of the input ports before the
limit is reached. limit is reached.
See also @scheme[input-port-append], which concatenates input streams See also @racket[input-port-append], which concatenates input streams
instead of interleaving them.} instead of interleaving them.}
@ -304,9 +304,9 @@ instead of interleaving them.}
'("Opening a null output port")]{ '("Opening a null output port")]{
Creates} and returns an output port that discards all output sent to it Creates} and returns an output port that discards all output sent to it
(without blocking). The @scheme[name] argument is used as the port's (without blocking). The @racket[name] argument is used as the port's
name. If the @scheme[special-ok?] argument is true, then the name. If the @racket[special-ok?] argument is true, then the
resulting port supports @scheme[write-special], otherwise it does not.} resulting port supports @racket[write-special], otherwise it does not.}
@defproc[(peeking-input-port [in input-port?] @defproc[(peeking-input-port [in input-port?]
@ -315,14 +315,14 @@ resulting port supports @scheme[write-special], otherwise it does not.}
input-port]{ input-port]{
Returns an input port whose content is determined by peeking into Returns an input port whose content is determined by peeking into
@scheme[in]. In other words, the resulting port contains an internal @racket[in]. In other words, the resulting port contains an internal
skip count, and each read of the port peeks into @scheme[in] with the skip count, and each read of the port peeks into @racket[in] with the
internal skip count, and then increments the skip count according to internal skip count, and then increments the skip count according to
the amount of data successfully peeked. the amount of data successfully peeked.
The optional @scheme[name] argument is the name of the resulting The optional @racket[name] argument is the name of the resulting
port. The @scheme[skip] argument is the port initial skip count, and port. The @racket[skip] argument is the port initial skip count, and
it defaults to @scheme[0]. it defaults to @racket[0].
The resulting port's initial position is @racket[0], no matter the The resulting port's initial position is @racket[0], no matter the
position of @racket[in]. position of @racket[in].
@ -359,24 +359,24 @@ the peeking port, we end up skipping over the @litchar{456} in the port.
(lambda (msg port) (error ...))]) (lambda (msg port) (error ...))])
input-port?]{ input-port?]{
Produces an input port that draws bytes from @scheme[in], but converts Produces an input port that draws bytes from @racket[in], but converts
the byte stream using @scheme[(bytes-open-converter encoding-str the byte stream using @racket[(bytes-open-converter encoding-str
"UTF-8")]. In addition, if @scheme[convert-newlines?] is true, then "UTF-8")]. In addition, if @racket[convert-newlines?] is true, then
decoded sequences that correspond to UTF-8 encodings of @scheme["\r\n"], decoded sequences that correspond to UTF-8 encodings of @racket["\r\n"],
@scheme["\r\x85"], @scheme["\r"], @scheme["\x85"], and @scheme["\u2028"] @racket["\r\x85"], @racket["\r"], @racket["\x85"], and @racket["\u2028"]
are all converted to the UTF-8 encoding of @scheme["\n"]. are all converted to the UTF-8 encoding of @racket["\n"].
If @scheme[error-bytes] is provided and not @scheme[#f], then the If @racket[error-bytes] is provided and not @racket[#f], then the
given byte sequence is used in place of bytes from @scheme[in] that given byte sequence is used in place of bytes from @racket[in] that
trigger conversion errors. Otherwise, if a conversion is encountered, trigger conversion errors. Otherwise, if a conversion is encountered,
@scheme[enc-error] is called, which must raise an exception. @racket[enc-error] is called, which must raise an exception.
If @scheme[close?] is true, then closing the result input port also If @racket[close?] is true, then closing the result input port also
closes @scheme[in]. The @scheme[name] argument is used as the name of closes @racket[in]. The @racket[name] argument is used as the name of
the result input port. the result input port.
In non-buffered mode, the resulting input port attempts to draw bytes In non-buffered mode, the resulting input port attempts to draw bytes
from @scheme[in] only as needed to satisfy requests. Toward that end, from @racket[in] only as needed to satisfy requests. Toward that end,
the input port assumes that at least @math{n} bytes must be read to the input port assumes that at least @math{n} bytes must be read to
satisfy a request for @math{n} bytes. (This is true even if the port satisfy a request for @math{n} bytes. (This is true even if the port
has already drawn some bytes, as long as those bytes form an has already drawn some bytes, as long as those bytes form an
@ -393,30 +393,30 @@ incomplete encoding sequence.)}
(lambda (msg port) (error ...))]) (lambda (msg port) (error ...))])
output-port?]{ output-port?]{
Produces an output port that directs bytes to @scheme[out], but Produces an output port that directs bytes to @racket[out], but
converts its byte stream using @scheme[(bytes-open-converter "UTF-8" converts its byte stream using @racket[(bytes-open-converter "UTF-8"
encoding-str)]. In addition, if @scheme[newline-bytes] is not encoding-str)]. In addition, if @racket[newline-bytes] is not
@scheme[#f], then byets written to the port that are the UTF-8 @racket[#f], then byets written to the port that are the UTF-8
encoding of @scheme["\n"] are first converted to encoding of @racket["\n"] are first converted to
@scheme[newline-bytes] (before applying the convert from UTF-8 to @racket[newline-bytes] (before applying the convert from UTF-8 to
@scheme[encoding-str]). @racket[encoding-str]).
If @scheme[error-bytes] is provided and not @scheme[#f], then the If @racket[error-bytes] is provided and not @racket[#f], then the
given byte sequence is used in place of bytes send to the output port given byte sequence is used in place of bytes send to the output port
that trigger conversion errors. Otherwise, @scheme[enc-error] is that trigger conversion errors. Otherwise, @racket[enc-error] is
called, which must raise an exception. called, which must raise an exception.
If @scheme[close?] is true, then closing the result output port also If @racket[close?] is true, then closing the result output port also
closes @scheme[out]. The @scheme[name] argument is used as the name of closes @racket[out]. The @racket[name] argument is used as the name of
the result output port. the result output port.
The resulting port supports buffering, and the initial buffer mode is The resulting port supports buffering, and the initial buffer mode is
@scheme[(or (file-stream-buffer-mode out) 'block)]. In @scheme['block] @racket[(or (file-stream-buffer-mode out) 'block)]. In @racket['block]
mode, the port's buffer is flushed only when it is full or a flush is mode, the port's buffer is flushed only when it is full or a flush is
requested explicitly. In @scheme['line] mode, the buffer is flushed requested explicitly. In @racket['line] mode, the buffer is flushed
whenever a newline or carriage-return byte is written to the port. In whenever a newline or carriage-return byte is written to the port. In
@scheme['none] mode, the port's buffer is flushed after every write. @racket['none] mode, the port's buffer is flushed after every write.
Implicit flushes for @scheme['line] or @scheme['none] leave bytes in Implicit flushes for @racket['line] or @racket['none] leave bytes in
the buffer when they are part of an incomplete encoding sequence. the buffer when they are part of an incomplete encoding sequence.
The resulting output port does not support atomic writes. An explicit The resulting output port does not support atomic writes. An explicit
@ -428,13 +428,13 @@ recently written bytes form an incomplete encoding sequence.}
[close? any/c #f]) [close? any/c #f])
input-port?]{ input-port?]{
Returns an input port that draws directly from @scheme[in]. Closing Returns an input port that draws directly from @racket[in]. Closing
the resulting port closes @scheme[in] only if @scheme[close?] is the resulting port closes @racket[in] only if @racket[close?] is
@scheme[#t]. @racket[#t].
The new port is initialized with the @tech{port read handler} of The new port is initialized with the @tech{port read handler} of
@scheme[in], but setting the handler on the result port does not @racket[in], but setting the handler on the result port does not
affect reading directly from @scheme[in].} affect reading directly from @racket[in].}
@defproc[(dup-output-port [out output-port?] @defproc[(dup-output-port [out output-port?]
@ -442,12 +442,12 @@ affect reading directly from @scheme[in].}
output-port?]{ output-port?]{
Returns an output port that propagates data directly to Returns an output port that propagates data directly to
@scheme[out]. Closing the resulting port closes @scheme[out] only if @racket[out]. Closing the resulting port closes @racket[out] only if
@scheme[close?] is @scheme[#t]. @racket[close?] is @racket[#t].
The new port is initialized with the @tech{port display handler} and The new port is initialized with the @tech{port display handler} and
@tech{port write handler} of @scheme[out], but setting the handlers on @tech{port write handler} of @racket[out], but setting the handlers on
the result port does not affect writing directly to @scheme[out].} the result port does not affect writing directly to @racket[out].}
@ -458,27 +458,27 @@ the result port does not affect writing directly to @scheme[out].}
[close? any/c #t]) [close? any/c #t])
input-port?]{ input-port?]{
Produces an input port that is equivalent to @scheme[in] except in how Produces an input port that is equivalent to @racket[in] except in how
it reports location information. The resulting port's content starts it reports location information. The resulting port's content starts
with the remaining content of @scheme[in], and it starts at the given with the remaining content of @racket[in], and it starts at the given
line, column, and position. A @scheme[#f] for the line or column means line, column, and position. A @racket[#f] for the line or column means
that the line and column will always be reported as @scheme[#f]. that the line and column will always be reported as @racket[#f].
The @scheme[line] and @scheme[column] values are used only if line The @racket[line] and @racket[column] values are used only if line
counting is enabled for @scheme[in] and for the resulting port, counting is enabled for @racket[in] and for the resulting port,
typically through @scheme[port-count-lines!]. The @scheme[column] typically through @racket[port-count-lines!]. The @racket[column]
value determines the column for the first line (i.e., the one numbered value determines the column for the first line (i.e., the one numbered
@scheme[line]), and later lines start at column @scheme[0]. The given @racket[line]), and later lines start at column @racket[0]. The given
@scheme[position] is used even if line counting is not enabled. @racket[position] is used even if line counting is not enabled.
When line counting is on for the resulting port, reading from When line counting is on for the resulting port, reading from
@scheme[in] instead of the resulting port increments location reports @racket[in] instead of the resulting port increments location reports
from the resulting port. Otherwise, the resulting port's position does from the resulting port. Otherwise, the resulting port's position does
not increment when data is read from @scheme[in]. not increment when data is read from @racket[in].
If @scheme[close?] is true, then closing the resulting port also If @racket[close?] is true, then closing the resulting port also
closes @scheme[in]. If @scheme[close?] is @scheme[#f], then closing closes @racket[in]. If @racket[close?] is @racket[#f], then closing
the resulting port does not close @scheme[in].} the resulting port does not close @racket[in].}
@defproc[(relocate-output-port [out output-port?] @defproc[(relocate-output-port [out output-port?]
@ -488,7 +488,7 @@ the resulting port does not close @scheme[in].}
[close? any/c #t]) [close? any/c #t])
output-port?]{ output-port?]{
Like @scheme[relocate-input-port], but for output ports.} Like @racket[relocate-input-port], but for output ports.}
@defproc[(transplant-input-port [in input-port?] @defproc[(transplant-input-port [in input-port?]
@ -504,15 +504,15 @@ Like @scheme[relocate-input-port], but for output ports.}
[count-lines! (-> any) void]) [count-lines! (-> any) void])
input-port?]{ input-port?]{
Like @scheme[relocate-input-port], except that arbitrary position Like @racket[relocate-input-port], except that arbitrary position
information can be produced (when line counting is enabled) via information can be produced (when line counting is enabled) via
@scheme[get-location], which used as for @scheme[make-input-port]. If @racket[get-location], which used as for @racket[make-input-port]. If
@scheme[get-location] is @scheme[#f], then the port counts lines in @racket[get-location] is @racket[#f], then the port counts lines in
the usual way starting from @scheme[init-pos], independent of the usual way starting from @racket[init-pos], independent of
locations reported by @scheme[in]. locations reported by @racket[in].
If @scheme[count-lines!] is supplied, it is called when line counting If @racket[count-lines!] is supplied, it is called when line counting
is enabled for the resulting port. The default is @scheme[void].} is enabled for the resulting port. The default is @racket[void].}
@defproc[(transplant-output-port [in input-port?] @defproc[(transplant-output-port [in input-port?]
[get-location (or/c [get-location (or/c
@ -527,7 +527,7 @@ is enabled for the resulting port. The default is @scheme[void].}
[count-lines! (-> any) void]) [count-lines! (-> any) void])
output-port?]{ output-port?]{
Like @scheme[transplant-input-port], but for output ports.} Like @racket[transplant-input-port], but for output ports.}
@defproc[(filter-read-input-port [in input-port?] @defproc[(filter-read-input-port [in input-port?]
[read-wrap (bytes? (or/c exact-nonnegative-integer? [read-wrap (bytes? (or/c exact-nonnegative-integer?
@ -572,10 +572,10 @@ closes @racket[in].}
[close? any/c #t]) [close? any/c #t])
input-port?]{ input-port?]{
Produces an input port that that is equivalent to @scheme[in], except Produces an input port that that is equivalent to @racket[in], except
that when @scheme[in] produces a procedure to access a special value, that when @racket[in] produces a procedure to access a special value,
@scheme[proc] is applied to the procedure to allow the special value @racket[proc] is applied to the procedure to allow the special value
to be replaced with an alternative. The @scheme[proc] is called with to be replaced with an alternative. The @racket[proc] is called with
the special-value procedure and the byte string that was given to the the special-value procedure and the byte string that was given to the
port's read or peek function (see @racket[make-input-port]), and the port's read or peek function (see @racket[make-input-port]), and the
result is used as te read or peek function's result. The result is used as te read or peek function's result. The
@ -583,7 +583,7 @@ result is used as te read or peek function's result. The
special value, but the byte string is guaranteed only to hold at least special value, but the byte string is guaranteed only to hold at least
one byte. one byte.
If @scheme[close?] is true, then closing the resulting input port also If @racket[close?] is true, then closing the resulting input port also
closes @racket[in].} closes @racket[in].}
@; ---------------------------------------------------------------------- @; ----------------------------------------------------------------------
@ -594,23 +594,23 @@ closes @racket[in].}
@defproc[(eof-evt [in input-port?]) evt?]{ @defproc[(eof-evt [in input-port?]) evt?]{
Returns a @tech{synchronizable event} is that is ready when Returns a @tech{synchronizable event} is that is ready when
@scheme[in] produces an @scheme[eof]. If @scheme[in] produces a @racket[in] produces an @racket[eof]. If @racket[in] produces a
mid-stream @scheme[eof], the @scheme[eof] is consumed by the event mid-stream @racket[eof], the @racket[eof] is consumed by the event
only if the event is chosen in a synchronization.} only if the event is chosen in a synchronization.}
@defproc[(read-bytes-evt [k exact-nonnegative-integer?] [in input-port?]) @defproc[(read-bytes-evt [k exact-nonnegative-integer?] [in input-port?])
evt?]{ evt?]{
Returns a @tech{synchronizable event} is that is ready when @scheme[k] Returns a @tech{synchronizable event} is that is ready when @racket[k]
bytes can be read from @scheme[in], or when an end-of-file is bytes can be read from @racket[in], or when an end-of-file is
encountered in @scheme[in]. If @scheme[k] is @scheme[0], then the encountered in @racket[in]. If @racket[k] is @racket[0], then the
event is ready immediately with @scheme[""]. For non-zero @scheme[k], event is ready immediately with @racket[""]. For non-zero @racket[k],
if no bytes are available before an end-of-file, the event's result is if no bytes are available before an end-of-file, the event's result is
@scheme[eof]. Otherwise the event's result is a byte string of up to @racket[eof]. Otherwise the event's result is a byte string of up to
@scheme[k] bytes, which contains as many bytes as are available (up to @racket[k] bytes, which contains as many bytes as are available (up to
@scheme[k]) before an available end-of-file. (The result is a byte @racket[k]) before an available end-of-file. (The result is a byte
string on less than @scheme[k] bytes only when an end-of-file is string on less than @racket[k] bytes only when an end-of-file is
encountered.) encountered.)
Bytes are read from the port if and only if the event is chosen in a Bytes are read from the port if and only if the event is chosen in a
@ -621,7 +621,7 @@ The event can be synchronized multiple times---event
concurrently---and each synchronization corresponds to a distinct read concurrently---and each synchronization corresponds to a distinct read
request. request.
The @scheme[in] must support progress events, and it must not produce The @racket[in] must support progress events, and it must not produce
a special non-byte value during the read attempt.} a special non-byte value during the read attempt.}
@ -629,14 +629,14 @@ a special non-byte value during the read attempt.}
[in input-port?]) [in input-port?])
evt?]{ evt?]{
Like @scheme[read-bytes-evt], except that the read bytes are placed Like @racket[read-bytes-evt], except that the read bytes are placed
into @scheme[bstr], and the number of bytes to read corresponds to into @racket[bstr], and the number of bytes to read corresponds to
@scheme[(bytes-length bstr)]. The event's result is either @racket[(bytes-length bstr)]. The event's result is either
@scheme[eof] or the number of read bytes. @racket[eof] or the number of read bytes.
The @scheme[bstr] may be mutated any time after the first The @racket[bstr] may be mutated any time after the first
synchronization attempt on the event. If the event is not synchronized synchronization attempt on the event. If the event is not synchronized
multiple times concurrently, @scheme[bstr-bytes] is never mutated by multiple times concurrently, @racket[bstr-bytes] is never mutated by
the event after it is chosen in a synchronization (no matter how many the event after it is chosen in a synchronization (no matter how many
synchronization attempts preceded the choice). Thus, the event may be synchronization attempts preceded the choice). Thus, the event may be
sensibly used multiple times until a successful choice, but should not sensibly used multiple times until a successful choice, but should not
@ -646,15 +646,15 @@ be used in multiple concurrent synchronizations.}
@defproc[(read-bytes-avail!-evt [bstr (and/c bytes? (not/c immutable?))] [in input-port?]) @defproc[(read-bytes-avail!-evt [bstr (and/c bytes? (not/c immutable?))] [in input-port?])
evt?]{ evt?]{
Like @scheme[read-bytes!-evt], except that the event reads only as Like @racket[read-bytes!-evt], except that the event reads only as
many bytes as are immediately available, after at least one byte or many bytes as are immediately available, after at least one byte or
one @scheme[eof] becomes available.} one @racket[eof] becomes available.}
@defproc[(read-string-evt [k exact-nonnegative-integer?] [in input-port?]) @defproc[(read-string-evt [k exact-nonnegative-integer?] [in input-port?])
evt?]{ evt?]{
Like @scheme[read-bytes-evt], but for character strings instead of Like @racket[read-bytes-evt], but for character strings instead of
byte strings.} byte strings.}
@ -662,7 +662,7 @@ byte strings.}
[in input-port?]) [in input-port?])
evt?]{ evt?]{
Like @scheme[read-bytes!-evt], but for a character string instead of Like @racket[read-bytes!-evt], but for a character string instead of
a byte string.} a byte string.}
@ -671,8 +671,8 @@ a byte string.}
evt?]{ evt?]{
Returns a @tech{synchronizable event} that is ready when a line of Returns a @tech{synchronizable event} that is ready when a line of
characters or end-of-file can be read from @scheme[inport]. The characters or end-of-file can be read from @racket[inport]. The
meaning of @scheme[mode] is the same as for @scheme[read-line]. The meaning of @racket[mode] is the same as for @racket[read-line]. The
event result is the read line of characters (not including the line event result is the read line of characters (not including the line
separator). separator).
@ -685,7 +685,7 @@ bytes in the port's stream.}
[mode (or/c 'linefeed 'return 'return-linefeed 'any 'any-one)]) [mode (or/c 'linefeed 'return 'return-linefeed 'any 'any-one)])
evt?]{ evt?]{
Like @scheme[read-line-evt], but returns a byte string instead of a Like @racket[read-line-evt], but returns a byte string instead of a
string.} string.}
@defproc*[([(peek-bytes-evt [k exact-nonnegative-integer?] [skip exact-nonnegative-integer?] @defproc*[([(peek-bytes-evt [k exact-nonnegative-integer?] [skip exact-nonnegative-integer?]
@ -697,11 +697,11 @@ string.}
[(peek-string-evt [k exact-nonnegative-integer?] [in input-port?]) evt?] [(peek-string-evt [k exact-nonnegative-integer?] [in input-port?]) evt?]
[(peek-string!-evt [str (and/c string? (not/c immutable?))] [in input-port?]) evt?])]{ [(peek-string!-evt [str (and/c string? (not/c immutable?))] [in input-port?]) evt?])]{
Like the @scheme[read-...-evt] functions, but for peeking. The Like the @racket[read-...-evt] functions, but for peeking. The
@scheme[skip] argument indicates the number of bytes to skip, and @racket[skip] argument indicates the number of bytes to skip, and
@scheme[progress] indicates an event that effectively cancels the peek @racket[progress] indicates an event that effectively cancels the peek
(so that the event never becomes ready). The @scheme[progress] (so that the event never becomes ready). The @racket[progress]
argument can be @scheme[#f], in which case the event is never argument can be @racket[#f], in which case the event is never
cancelled.} cancelled.}
@ -709,12 +709,12 @@ cancelled.}
[in input-port?]) any]{ [in input-port?]) any]{
Returns a @tech{synchronizable event} that is ready when Returns a @tech{synchronizable event} that is ready when
@scheme[pattern] matches the stream of bytes/characters from @racket[pattern] matches the stream of bytes/characters from
@scheme[in]; see also @scheme[regexp-match]. The event's value is the @racket[in]; see also @racket[regexp-match]. The event's value is the
result of the match, in the same form as the result of result of the match, in the same form as the result of
@scheme[regexp-match]. @racket[regexp-match].
If @scheme[pattern] does not require a start-of-stream match, then If @racket[pattern] does not require a start-of-stream match, then
bytes skipped to complete the match are read and discarded when the bytes skipped to complete the match are read and discarded when the
event is chosen in a synchronization. event is chosen in a synchronization.
@ -722,16 +722,16 @@ Bytes are read from the port if and only if the event is chosen in a
synchronization, and the returned match always represents contiguous synchronization, and the returned match always represents contiguous
bytes in the port's stream. If not-yet-available bytes from the port bytes in the port's stream. If not-yet-available bytes from the port
might contribute to the match, the event is not ready. Similarly, if might contribute to the match, the event is not ready. Similarly, if
@scheme[pattern] begins with a start-of-stream @litchar{^} and the @racket[pattern] begins with a start-of-stream @litchar{^} and the
@scheme[pattern] does not initially match, then the event cannot @racket[pattern] does not initially match, then the event cannot
become ready until bytes have been read from the port. become ready until bytes have been read from the port.
The event can be synchronized multiple times---even concurrently---and The event can be synchronized multiple times---even concurrently---and
each synchronization corresponds to a distinct match request. each synchronization corresponds to a distinct match request.
The @scheme[in] port must support progress events. If @scheme[in] The @racket[in] port must support progress events. If @racket[in]
returns a special non-byte value during the match attempt, it is returns a special non-byte value during the match attempt, it is
treated like @scheme[eof].} treated like @racket[eof].}
@; ---------------------------------------------------------------------- @; ----------------------------------------------------------------------
@ -743,35 +743,35 @@ treated like @scheme[eof].}
[out output-port?]) [out output-port?])
void?]{ void?]{
Reads data from @scheme[in], converts it using Reads data from @racket[in], converts it using
@scheme[(bytes-open-converter from-encoding-string @racket[(bytes-open-converter from-encoding-string
to-encoding-string)] and writes the converted bytes to to-encoding-string)] and writes the converted bytes to
@scheme[out]. The @scheme[convert-stream] procedure returns after @racket[out]. The @racket[convert-stream] procedure returns after
reaching @scheme[eof] in @scheme[in]. reaching @racket[eof] in @racket[in].
If opening the converter fails, the @exnraise[exn:fail]. Similarly, if If opening the converter fails, the @exnraise[exn:fail]. Similarly, if
a conversion error occurs at any point while reading @scheme[in], then a conversion error occurs at any point while reading @racket[in], then
@exnraise[exn:fail].} @exnraise[exn:fail].}
@defproc[(copy-port [in input-port?] [out output-port?] ...+) void?]{ @defproc[(copy-port [in input-port?] [out output-port?] ...+) void?]{
Reads data from @scheme[in] and writes it back out to @scheme[out], Reads data from @racket[in] and writes it back out to @racket[out],
returning when @scheme[in] produces @scheme[eof]. The copy is returning when @racket[in] produces @racket[eof]. The copy is
efficient, and it is without significant buffer delays (i.e., a byte efficient, and it is without significant buffer delays (i.e., a byte
that becomes available on @scheme[in] is immediately transferred to that becomes available on @racket[in] is immediately transferred to
@scheme[out], even if future reads on @scheme[in] must block). If @racket[out], even if future reads on @racket[in] must block). If
@scheme[in] produces a special non-byte value, it is transferred to @racket[in] produces a special non-byte value, it is transferred to
@scheme[out] using @scheme[write-special]. @racket[out] using @racket[write-special].
This function is often called from a ``background'' thread to This function is often called from a ``background'' thread to
continuously pump data from one stream to another. continuously pump data from one stream to another.
If multiple @scheme[out]s are provided, case data from @scheme[in] is If multiple @racket[out]s are provided, case data from @racket[in] is
written to every @scheme[out]. The different @scheme[out]s block written to every @racket[out]. The different @racket[out]s block
output to each other, because each block of data read from @scheme[in] output to each other, because each block of data read from @racket[in]
is written completely to one @scheme[out] before moving to the next is written completely to one @racket[out] before moving to the next
@scheme[out]. The @scheme[out]s are written in the provided order, so @racket[out]. The @racket[out]s are written in the provided order, so
non-blocking ports (e.g., to a file) should be placed first in the non-blocking ports (e.g., to a file) should be placed first in the
argument list.} argument list.}