1 ! Copyright (C) 2009 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: help.markup help.syntax kernel math io ;
8 { "stream" "an input stream" } { "limit" integer } { "mode" { $link stream-throws } " or " { $link stream-eofs } }
9 { "stream'" "an input stream" }
11 { $description "Constructs a new " { $link limited-stream } " from an existing stream. User code should use " { $link limit } " or " { $link limit-input } "." } ;
15 { "stream" "an input stream" } { "limit" integer } { "mode" { $link stream-throws } " or " { $link stream-eofs } }
16 { "stream'" "a stream" }
18 { $description "Changes a decoder's stream to be a limited stream, or wraps " { $snippet "stream" } " in a " { $link limited-stream } "." }
19 { $examples "Throwing an exception:"
21 "USING: continuations io io.streams.limited io.streams.string"
22 "kernel prettyprint ;"
24 " \"123456\" <string-reader> 3 stream-throws limit"
25 " 100 swap stream-read ."
33 { underlying "123456" }
37 { mode stream-throws }
44 "Returning " { $link f } " on exhaustion:"
46 "USING: accessors continuations io io.streams.limited"
47 "io.streams.string kernel prettyprint ;"
48 "\"123456\" <string-reader> 3 stream-eofs limit"
49 "100 swap stream-read ."
56 { "stream" "an input stream" }
57 { "stream'" "a stream" }
59 { $description "Returns the underlying stream of a limited stream." } ;
63 { "value" "a limited-stream class" }
65 { $description "Limited streams wrap other streams, changing their behavior to throw an exception or return " { $link f } " upon exhaustion." } ;
69 { "limit" integer } { "mode" { $link stream-throws } " or " { $link stream-eofs } }
71 { $description "Wraps the current " { $link input-stream } " in a " { $link limited-stream } "." } ;
74 { $description "Returns the underlying stream of the limited-stream stored in " { $link input-stream } "." } ;
78 { "value" { $link stream-throws } " or " { $link stream-eofs } }
80 { $description "If the " { $slot "mode" } " of a limited stream is set to this singleton, the stream will return " { $link f } " upon exhaustion." } ;
84 { "value" { $link stream-throws } " or " { $link stream-eofs } }
86 { $description "If the " { $slot "mode" } " of a limited stream is set to this singleton, the stream will throw " { $link limit-exceeded } " upon exhaustion." } ;
88 { stream-eofs stream-throws } related-words
90 ARTICLE: "io.streams.limited" "Limited input streams"
91 "The " { $vocab-link "io.streams.limited" } " vocabulary wraps a stream to behave as if it had only a limited number of bytes, either throwing an error or returning " { $link f } " upon reaching the end. Limiting a non-seekable stream keeps a byte count and triggers the end-of-stream behavior when this byte count has been reached. However, limiting a seekable stream creates a window of bytes that supports seeking and re-reading of bytes in that window." $nl
92 "Wrap a stream in a limited stream:"
93 { $subsections limit }
94 "Wrap the current " { $link input-stream } " in a limited stream:"
95 { $subsections limit-input }
96 "Unlimits a limited stream:"
97 { $subsections unlimited }
98 "Unlimits the current " { $link input-stream } ":"
99 { $subsections unlimited-input }
100 "Make a limited stream throw an exception on exhaustion:"
101 { $subsections stream-throws }
102 "Make a limited stream return " { $link f } " on exhaustion:"
103 { $subsections stream-eofs } ;
105 ABOUT: "io.streams.limited"