-
-
Save apeiros/acbd5682c73cb74eeaf21e0db82338d7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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