make temporary nesting work better with limited streams, fix a bug with unlimit
parent
d74db52204
commit
6f12877418
|
@ -81,7 +81,7 @@ ARTICLE: "io.streams.limited" "Limited input streams"
|
||||||
"Unlimits a limited stream:"
|
"Unlimits a limited stream:"
|
||||||
{ $subsection unlimit }
|
{ $subsection unlimit }
|
||||||
"Unlimits the current " { $link input-stream } ":"
|
"Unlimits the current " { $link input-stream } ":"
|
||||||
{ $subsection limit-input }
|
{ $subsection unlimit-input }
|
||||||
"Make a limited stream throw an exception on exhaustion:"
|
"Make a limited stream throw an exception on exhaustion:"
|
||||||
{ $subsection stream-throws }
|
{ $subsection stream-throws }
|
||||||
"Make a limited stream return " { $link f } " on exhaustion:"
|
"Make a limited stream return " { $link f } " on exhaustion:"
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
USING: io io.streams.limited io.encodings io.encodings.string
|
USING: io io.streams.limited io.encodings io.encodings.string
|
||||||
io.encodings.ascii io.encodings.binary io.streams.byte-array
|
io.encodings.ascii io.encodings.binary io.streams.byte-array
|
||||||
namespaces tools.test strings kernel io.streams.string accessors ;
|
namespaces tools.test strings kernel io.streams.string accessors
|
||||||
|
io.encodings.utf8 io.files destructors ;
|
||||||
IN: io.streams.limited.tests
|
IN: io.streams.limited.tests
|
||||||
|
|
||||||
[ ] [
|
[ ] [
|
||||||
|
@ -59,3 +60,19 @@ IN: io.streams.limited.tests
|
||||||
"abc" <string-reader> 3 stream-eofs limit unlimit
|
"abc" <string-reader> 3 stream-eofs limit unlimit
|
||||||
"abc" <string-reader> =
|
"abc" <string-reader> =
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
|
[ t ]
|
||||||
|
[
|
||||||
|
"abc" <string-reader> 3 stream-eofs limit unlimit
|
||||||
|
"abc" <string-reader> =
|
||||||
|
] unit-test
|
||||||
|
|
||||||
|
[ t ]
|
||||||
|
[
|
||||||
|
[
|
||||||
|
"resource:license.txt" utf8 <file-reader> &dispose
|
||||||
|
3 stream-eofs limit unlimit
|
||||||
|
"resource:license.txt" utf8 <file-reader> &dispose
|
||||||
|
[ decoder? ] both?
|
||||||
|
] with-destructors
|
||||||
|
] unit-test
|
||||||
|
|
|
@ -5,7 +5,7 @@ USING: kernel math io io.encodings destructors accessors
|
||||||
sequences namespaces byte-vectors fry combinators ;
|
sequences namespaces byte-vectors fry combinators ;
|
||||||
IN: io.streams.limited
|
IN: io.streams.limited
|
||||||
|
|
||||||
TUPLE: limited-stream stream count limit mode ;
|
TUPLE: limited-stream stream count limit mode stack ;
|
||||||
|
|
||||||
SINGLETONS: stream-throws stream-eofs ;
|
SINGLETONS: stream-throws stream-eofs ;
|
||||||
|
|
||||||
|
@ -24,13 +24,24 @@ M: decoder limit ( stream limit mode -- stream' )
|
||||||
M: object limit ( stream limit mode -- stream' )
|
M: object limit ( stream limit mode -- stream' )
|
||||||
<limited-stream> ;
|
<limited-stream> ;
|
||||||
|
|
||||||
: unlimit ( stream -- stream' )
|
GENERIC: unlimit ( stream -- stream' )
|
||||||
|
|
||||||
|
M: decoder unlimit ( stream -- stream' )
|
||||||
[ stream>> ] change-stream ;
|
[ stream>> ] change-stream ;
|
||||||
|
|
||||||
|
M: object unlimit ( stream -- stream' )
|
||||||
|
stream>> stream>> ;
|
||||||
|
|
||||||
: limit-input ( limit mode -- ) input-stream [ -rot limit ] change ;
|
: limit-input ( limit mode -- ) input-stream [ -rot limit ] change ;
|
||||||
|
|
||||||
: unlimit-input ( -- ) input-stream [ unlimit ] change ;
|
: unlimit-input ( -- ) input-stream [ unlimit ] change ;
|
||||||
|
|
||||||
|
: with-unlimited-stream ( stream quot -- )
|
||||||
|
[ clone unlimit ] dip call ; inline
|
||||||
|
|
||||||
|
: with-limited-stream ( stream limit mode quot -- )
|
||||||
|
[ limit ] dip call ; inline
|
||||||
|
|
||||||
ERROR: limit-exceeded ;
|
ERROR: limit-exceeded ;
|
||||||
|
|
||||||
ERROR: bad-stream-mode mode ;
|
ERROR: bad-stream-mode mode ;
|
||||||
|
|
Loading…
Reference in New Issue