class

Scroll::FileSource

Inherits Scroll::Source < Reference < Object

Follows a file the way tail -F does: reads appended bytes live, reopens across rotation (the name now points at a different inode), and seeks back to 0 across truncation (the file shrank in place). When there is nothing new it sleep-polls, which yields to the event loop. read only ever returns 0 when a termination condition (--pid gone, or the Linux writer-idle timer) fires after the current file has been drained to EOF, so no trailing bytes are lost.

Constants

NEWLINE = '\n'.ord.to_u8
SCAN_BLOCK = 8192

Constructors

new(path : String, poll : Time::Span, *, from_start : Bool = false, prime_lines : Int32 = 0, pid : Int32 | Nil = nil, watch_proc : Bool = false, watch_proc_timeout : Time::Span = 10.seconds)
Source

Class methods

tail_offset(file : File, lines : Int32) : Int64

Byte offset of the start of the last lines complete lines, or 0 when the file holds fewer than that. Scanned backwards in blocks, so priming from a huge log costs a read or two rather than a pass over the whole file.

Source

Instance methods

close
Source
read(buffer : Bytes) : Int32
Source