Skip to content

Instantly share code, notes, and snippets.

@apeiros
Last active October 2, 2018 09:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save apeiros/acbd5682c73cb74eeaf21e0db82338d7 to your computer and use it in GitHub Desktop.
Save apeiros/acbd5682c73cb74eeaf21e0db82338d7 to your computer and use it in GitHub Desktop.
def testing_seek(filename)
return nil if File.size(filename) < 3
File.open(filename, 'rb') do |fd|
buffer = "".b
fd.seek(-1, IO::SEEK_END)
until fd.pos.zero? || buffer[0, 3] == '---'
buffer = fd.read(1) + buffer
fd.seek(-2, IO::SEEK_CUR)
end
buffer[0, 3] == '---' ? buffer : nil
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment