Commit cf4ab10d authored by Shinya Maeda's avatar Shinya Maeda

Adopt ayufan script

parent a1638748
...@@ -96,28 +96,29 @@ module Gitlab ...@@ -96,28 +96,29 @@ module Gitlab
end end
def reverse_line def reverse_line
return if stream.size <= 0 stream.seek(0, IO::SEEK_END)
pos = 0
max = stream.size
debris = '' debris = ''
while (read_size = calc_read_size(pos, max)) > 0 while !(buf = read_backward(BUFFER_SIZE)).empty?
pos += read_size buf += debris
stream.seek(-pos, IO::SEEK_END)
buf = stream.read(read_size) + debris
debris, *lines = buf.each_line.to_a debris, *lines = buf.each_line.to_a
lines.reverse_each do |line| lines.reverse_each do |line|
yield(line.force_encoding('UTF-8')) yield(line.force_encoding('UTF-8'))
end end
end end
yield(debris.force_encoding('UTF-8')) yield(debris.force_encoding('UTF-8')) if !(debris).empty?
end end
def calc_read_size(pos, max) def read_backward(length)
remain = max - pos cur_offset = stream.tell
(remain > BUFFER_SIZE) ? BUFFER_SIZE : remain start = cur_offset - length
start = 0 if start < 0
stream.seek(start, IO::SEEK_SET)
stream.read(cur_offset - start).tap do
stream.seek(start, IO::SEEK_SET)
end
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment