Sha256: 3548ad0ad453558f73e710155c67b13b93b9151876e0b9c5b8d6e98cd3122cae

Contents?: true

Size: 371 Bytes

Versions: 43

Compression:

Stored size: 371 Bytes

Contents

class File
  def tail(n)
    buffer = 1024
    idx = size > buffer ? size - buffer : 0
    chunks = []
    lines = 0

    begin
      seek(idx)
      chunk = read(buffer)
      break unless chunk
      lines += chunk.count("\n")
      chunks.unshift chunk
      idx -= buffer
    end while lines < ( n + 1 ) && idx >= 0

    chunks.join('').split(/\n/).last(n)
  end
end

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
tailog-0.4.8 lib/tailog/ext/file.rb
tailog-0.4.7 lib/tailog/ext/file.rb
tailog-0.4.6 lib/tailog/ext/file.rb
tailog-0.4.5 lib/tailog/ext/file.rb
tailog-0.4.3 lib/tailog/ext/file.rb
tailog-0.4.2 lib/tailog/ext/file.rb
tailog-0.4.1 lib/tailog/ext/file.rb
tailog-0.4.0 lib/tailog/ext/file.rb
tailog-0.3.7 lib/tailog/ext/file.rb
tailog-0.3.6 lib/tailog/ext/file.rb
tailog-0.3.5 lib/tailog/ext/file.rb
tailog-0.3.4 lib/tailog/ext/file.rb
tailog-0.3.3 lib/tailog/ext/file.rb
tailog-0.3.2 lib/tailog/ext/file.rb
tailog-0.3.1 lib/tailog/ext/file.rb
tailog-0.3.0 lib/tailog/ext/file.rb
tailog-0.2.3 lib/tailog/ext/file.rb
tailog-0.2.2 lib/tailog/ext/file.rb
tailog-0.2.1 lib/tailog/ext/file.rb
tailog-0.2.0 lib/tailog/ext/file.rb