幸運なことに、私はそのようなユーティリティを少し前に書きました。https://github.com/bjourne/playground-factor/wiki/Tips-and-Tricks-Filesystem#tailing-a-fileを参照してください
USING: accessors io io.encodings.utf8 io.files io.monitors kernel namespaces ;
IN: examples.files.tail
: emit-changes ( monitor -- )
dup next-change drop
input-stream get output-stream get stream-copy* flush
emit-changes ;
: seek-input-end ( -- )
0 seek-end input-stream get stream>> stream-seek ;
: tail-file ( fname -- )
[
dup f <monitor> swap utf8 [
seek-input-end emit-changes
] with-file-reader
] with-monitors ;
あなたの問題は、に与えられた引用with-input-stream*
が暗黙的にストリームを閉じることです(each-line
そうします)。それがバグかどうかはわかりません。次のような単語を使用すると、ストリームを閉じずにストリーム全体を読み取ることができます。
: my-stream-contents* ( stream -- seq )
[ [ stream-read1 dup ] curry [ ] ] [ stream-exemplar produce-as nip ] bi ;
それで:
IN: scratchpad "/tmp/foo" utf8 <file-reader> [ my-stream-contents* print ] keep
file contents here
...
--- Data stack:
T{ decoder f ~input-port~ utf8 f }
IN: scratchpad my-stream-contents* print
more file contents here
...