M: object url-of drop f ;
TUPLE: html-writer data ;
+INSTANCE: html-writer output-stream
<PRIVATE
default-buffer-size get <buffer> >>buffer ; inline
TUPLE: input-port < buffered-port ;
+INSTANCE: input-port input-stream
M: input-port stream-element-type drop +byte+ ; inline
] if ;
TUPLE: output-port < buffered-port ;
+INSTANCE: output-port output-stream
: <output-port> ( handle -- output-port )
output-port <buffered-port> ;
CONSULT: output-stream-protocol duplex-stream out>> ;
CONSULT: formatted-output-stream-protocol duplex-stream out>> ;
+INSTANCE: duplex-stream input-stream
+INSTANCE: duplex-stream output-stream
+
: >duplex-stream< ( stream -- in out ) [ in>> ] [ out>> ] bi ; inline
M: duplex-stream stream-element-type
SINGLETONS: null-reader null-writer ;
UNION: null-stream null-reader null-writer ;
+INSTANCE: null-reader input-stream
+INSTANCE: null-writer output-stream
INSTANCE: null-writer plain-writer
M: null-stream dispose drop ;
! Readers
TUPLE: string-reader { underlying string read-only } { i array-capacity } ;
+INSTANCE: string-reader input-stream
M: string-reader stream-element-type drop +character+ ;
M: string-reader stream-read-unsafe sequence-read-unsafe ;
ERROR: stream-exhausted n stream word ;
TUPLE: throws-on-eof-stream stream ;
+INSTANCE: throws-on-eof-stream input-stream
C: <throws-on-eof-stream> throws-on-eof-stream
C: <ignore-close-stream> ignore-close-stream
TUPLE: style-stream < filter-writer style ;
+INSTANCE: style-stream output-stream
: do-nested-style ( style style-stream -- style stream )
[ style>> swap assoc-union ] [ stream>> ] bi ; inline
selection-color caret mark selecting? ;
TUPLE: pane-stream pane ;
+INSTANCE: pane-stream output-stream
C: <pane-stream> pane-stream
TUPLE: interactor < source-editor
output history flag mailbox thread waiting token-model word-model popup ;
+INSTANCE: interactor input-stream
+
: register-self ( interactor -- )
<mailbox> >>mailbox
self >>thread
CONSTANT: replacement-char HEX: fffd
TUPLE: decoder { stream read-only } { code read-only } { cr boolean } ;
+INSTANCE: decoder input-stream
ERROR: decode-error ;
GENERIC: <encoder> ( stream encoding -- newstream )
TUPLE: encoder { stream read-only } { code read-only } ;
+INSTANCE: encoder output-stream
ERROR: encode-error ;
! Test default input stream protocol methods
TUPLE: up-to-13-reader { i fixnum initial: 0 } ;
+INSTANCE: up-to-13-reader input-stream
M: up-to-13-reader stream-element-type drop +byte+ ; inline
M: up-to-13-reader stream-read1
! Test default output stream protocol methods
TUPLE: dumb-writer vector ;
+INSTANCE: dumb-writer output-stream
: <dumb-writer> ( -- x ) BV{ } clone dumb-writer boa ; inline
: stream-print ( str stream -- ) [ stream-write ] [ stream-nl ] bi ;
! Default streams
-SYMBOL: input-stream
-SYMBOL: output-stream
+MIXIN: input-stream
+MIXIN: output-stream
SYMBOL: error-stream
: readln ( -- str/f ) input-stream get stream-readln ; inline
[ stream-exemplar ] bi produce-as swap finalize-read-until ; inline
PRIVATE>
-M: object stream-read-unsafe rot 0 read-loop ;
-M: object stream-read-partial-unsafe stream-read-unsafe ; inline
-M: object stream-read-until read-until-loop ;
-M: object stream-readln
+M: input-stream stream-read-unsafe rot 0 read-loop ;
+M: input-stream stream-read-partial-unsafe stream-read-unsafe ; inline
+M: input-stream stream-read-until read-until-loop ;
+M: input-stream stream-readln
"\n" swap stream-read-until drop ; inline
-M: object stream-contents (stream-contents-by-length-or-block) ; inline
-M: object stream-seekable? drop f ; inline
-M: object stream-length drop f ; inline
-
-M: object stream-write [ stream-write1 ] curry each ; inline
-M: object stream-flush drop ; inline
-M: object stream-nl CHAR: \n swap stream-write1 ; inline
+M: input-stream stream-contents (stream-contents-by-length-or-block) ; inline
+M: input-stream stream-seekable? drop f ; inline
+M: input-stream stream-length drop f ; inline
+
+M: output-stream stream-write [ stream-write1 ] curry each ; inline
+M: output-stream stream-flush drop ; inline
+M: output-stream stream-nl CHAR: \n swap stream-write1 ; inline
+M: output-stream stream-seekable? drop f ; inline
+M: output-stream stream-length drop f ; inline
sequences sequences.private ;
IN: io.streams.byte-array
+INSTANCE: byte-vector output-stream
M: byte-vector stream-element-type drop +byte+ ;
: <byte-writer> ( encoding -- stream )
dup encoder? [ stream>> ] when >byte-array ; inline
TUPLE: byte-reader { underlying byte-array read-only } { i array-capacity } ;
+INSTANCE: byte-reader input-stream
M: byte-reader stream-element-type drop +byte+ ;
M: c-stream dispose* handle>> fclose ;
TUPLE: c-writer < c-stream ;
+INSTANCE: c-writer output-stream
: <c-writer> ( handle -- stream ) c-writer new-c-stream ;
M: c-writer stream-flush dup check-disposed handle>> fflush ;
TUPLE: c-reader < c-stream ;
+INSTANCE: c-reader input-stream
: <c-reader> ( handle -- stream ) c-reader new-c-stream ;
: <memory-stream> ( alien -- stream )
memory-stream boa ;
+INSTANCE: memory-stream input-stream
+
M: memory-stream stream-element-type drop +byte+ ;
M: memory-stream stream-read1
M: growable stream-write push-all ;
M: growable stream-flush drop ;
+INSTANCE: growable output-stream
INSTANCE: growable plain-writer
! Seeking
IN: benchmark.tcp-echo0
! Max size here is 26 2^ 1 - because array-capacity limits on 32bit platforms
-CONSTANT: test-size0 $[ 26 2^ 1 - ]
+CONSTANT: test-size0 $[ 25 2^ 1 - ]
MEMO: test-bytes ( n -- byte-array ) iota >byte-array ;
SINGLETON: curses-listener-stream
+INSTANCE: curses-listener-stream input-stream
+INSTANCE: curses-listener-stream output-stream
+
M: curses-listener-stream stream-readln
drop [ curses-stream-readln ] B{ } make utf8 decode ;
IN: io.streams.peek
TUPLE: peek-stream stream peeked ;
+INSTANCE: peek-stream input-stream
+INSTANCE: peek-stream output-stream
M: peek-stream dispose stream>> dispose ;
! Streams for testing
TUPLE: mb-writer lines last-line disposed ;
+INSTANCE: mb-writer output-stream
+
TUPLE: mb-reader lines disposed ;
+INSTANCE: mb-reader input-stream
+
: <mb-writer> ( -- mb-writer ) V{ } clone V{ } clone f mb-writer boa ;
: <mb-reader> ( -- mb-reader ) <mailbox> f mb-reader boa ;
: push-line ( line test-reader-stream -- ) lines>> mailbox-put ;
SYMBOL: completions
TUPLE: readline-reader { prompt initial: f } ;
+INSTANCE: readline-reader input-stream
+
M: readline-reader stream-readln
flush [ prompt>> dup [ " " append ] [ ] if readline ]
keep f >>prompt drop ;