unix support for stream seeking
parent
5f39a714be
commit
f6f716c4e3
|
@ -46,6 +46,9 @@ M: fd cancel-operation ( fd -- )
|
||||||
2bi
|
2bi
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
|
M: unix (stream-seek)
|
||||||
|
handle>> fd>> swap SEEK_SET lseek io-error ;
|
||||||
|
|
||||||
SYMBOL: +retry+ ! just try the operation again without blocking
|
SYMBOL: +retry+ ! just try the operation again without blocking
|
||||||
SYMBOL: +input+
|
SYMBOL: +input+
|
||||||
SYMBOL: +output+
|
SYMBOL: +output+
|
||||||
|
|
|
@ -27,6 +27,9 @@ M: buffer dispose* ptr>> free ;
|
||||||
: buffer-empty? ( buffer -- ? )
|
: buffer-empty? ( buffer -- ? )
|
||||||
fill>> zero? ; inline
|
fill>> zero? ; inline
|
||||||
|
|
||||||
|
: buffer-seek ( n buffer -- )
|
||||||
|
(>>pos) ; inline
|
||||||
|
|
||||||
: buffer-consume ( n buffer -- )
|
: buffer-consume ( n buffer -- )
|
||||||
[ + ] change-pos
|
[ + ] change-pos
|
||||||
dup [ pos>> ] [ fill>> ] bi <
|
dup [ pos>> ] [ fill>> ] bi <
|
||||||
|
|
|
@ -4,7 +4,7 @@ USING: math kernel io sequences io.buffers io.timeouts generic
|
||||||
byte-vectors system io.encodings math.order io.backend
|
byte-vectors system io.encodings math.order io.backend
|
||||||
continuations classes byte-arrays namespaces splitting
|
continuations classes byte-arrays namespaces splitting
|
||||||
grouping dlists assocs io.encodings.binary summary accessors
|
grouping dlists assocs io.encodings.binary summary accessors
|
||||||
destructors combinators ;
|
destructors combinators unix ;
|
||||||
IN: io.ports
|
IN: io.ports
|
||||||
|
|
||||||
SYMBOL: default-buffer-size
|
SYMBOL: default-buffer-size
|
||||||
|
@ -93,6 +93,12 @@ M: input-port stream-read-until ( seps port -- str/f sep/f )
|
||||||
] [ [ 2drop ] 2dip ] if
|
] [ [ 2drop ] 2dip ] if
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
|
HOOK: (stream-seek) os ( n stream -- )
|
||||||
|
|
||||||
|
M: input-port stream-seek ( n stream -- )
|
||||||
|
dup check-disposed
|
||||||
|
2dup buffer>> buffer-seek (stream-seek) ;
|
||||||
|
|
||||||
TUPLE: output-port < buffered-port ;
|
TUPLE: output-port < buffered-port ;
|
||||||
|
|
||||||
: <output-port> ( handle -- output-port )
|
: <output-port> ( handle -- output-port )
|
||||||
|
|
|
@ -50,6 +50,8 @@ M: object <decoder> f decoder boa ;
|
||||||
M: decoder stream-read1
|
M: decoder stream-read1
|
||||||
dup >decoder< decode-char fix-read1 ;
|
dup >decoder< decode-char fix-read1 ;
|
||||||
|
|
||||||
|
M: decoder stream-seek stream>> stream-seek ;
|
||||||
|
|
||||||
: fix-read ( stream string -- string )
|
: fix-read ( stream string -- string )
|
||||||
over cr>> [
|
over cr>> [
|
||||||
over cr-
|
over cr-
|
||||||
|
|
|
@ -15,6 +15,8 @@ GENERIC: stream-write ( seq stream -- )
|
||||||
GENERIC: stream-flush ( stream -- )
|
GENERIC: stream-flush ( stream -- )
|
||||||
GENERIC: stream-nl ( stream -- )
|
GENERIC: stream-nl ( stream -- )
|
||||||
|
|
||||||
|
GENERIC: stream-seek ( n stream -- )
|
||||||
|
|
||||||
: stream-print ( str stream -- ) [ stream-write ] keep stream-nl ;
|
: stream-print ( str stream -- ) [ stream-write ] keep stream-nl ;
|
||||||
|
|
||||||
! Default streams
|
! Default streams
|
||||||
|
@ -27,6 +29,7 @@ SYMBOL: error-stream
|
||||||
: read ( n -- seq ) input-stream get stream-read ;
|
: read ( n -- seq ) input-stream get stream-read ;
|
||||||
: read-until ( seps -- seq sep/f ) input-stream get stream-read-until ;
|
: read-until ( seps -- seq sep/f ) input-stream get stream-read-until ;
|
||||||
: read-partial ( n -- seq ) input-stream get stream-read-partial ;
|
: read-partial ( n -- seq ) input-stream get stream-read-partial ;
|
||||||
|
: seek ( n -- ) input-stream get stream-seek ;
|
||||||
|
|
||||||
: write1 ( elt -- ) output-stream get stream-write1 ;
|
: write1 ( elt -- ) output-stream get stream-write1 ;
|
||||||
: write ( seq -- ) output-stream get stream-write ;
|
: write ( seq -- ) output-stream get stream-write ;
|
||||||
|
@ -82,4 +85,4 @@ PRIVATE>
|
||||||
|
|
||||||
: stream-copy ( in out -- )
|
: stream-copy ( in out -- )
|
||||||
[ [ [ write ] each-block ] with-output-stream ]
|
[ [ [ write ] each-block ] with-output-stream ]
|
||||||
curry with-input-stream ;
|
curry with-input-stream ;
|
||||||
|
|
Loading…
Reference in New Issue