petoem / tail

Tailing library for Crystal - get and/or follow the end of a file/IO

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Tail

Tailing library for Crystal - get and/or follow the end of a file/IO

Installation

Add the dependency to your shard.yml:

dependencies:
  exec:
    github: j8r/tail

Usage

Tail

.follow(io : IO, delay = 0.1, &block)

Follows the new appended bytes of an IO

Tail::File

Constructors

.new(@file : ::File)

.new(file : String)

Instance Method

#last_lines(lines = 10, line_size = 1024) : Array(String)

Get the last n lines.

line_size is used to extract the end of the file, and then calculate the trailing lines

#follow(lines = 0, line_size = 1024, delay = 0.1, &block : String -> _)

Follow the end of a file

#watch(lines = 0, line_size = 1024, &block : String -> _)

(Linux Only) Use Inotify to yield newly added bytes from the file

Examples

require "tail"

Tail::File.new("file").follow do |str|
  print str
end

Tail::File.new("file").last_lines

License

Copyright (c) 2018 Julien Reichardt - ISC License

About

Tailing library for Crystal - get and/or follow the end of a file/IO

License:ISC License


Languages

Language:Crystal 100.0%