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