tkellem 0.9.0.beta8 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/backwards_file_reader.rb +38 -38
- data/lib/tkellem/version.rb +1 -1
- metadata +9 -6
@@ -1,48 +1,48 @@
|
|
1
1
|
class BackwardsFileReader
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
2
|
+
def self.scan(stream)
|
3
|
+
scanner = new(stream)
|
4
|
+
while line = scanner.readline
|
5
|
+
break unless yield(line)
|
6
|
+
end
|
7
|
+
scanner.sync
|
8
|
+
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
def initialize(stream)
|
11
|
+
@stream = stream
|
12
|
+
@stream.seek 0, IO::SEEK_END
|
13
|
+
@pos = @stream.pos
|
14
|
+
@offset = 0
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
@read_size = [4096, @pos].min
|
17
|
+
@line_buffer = []
|
18
|
+
end
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
20
|
+
def readline
|
21
|
+
if @line_buffer.size > 2 || @pos == 0
|
22
|
+
line = @line_buffer.pop
|
23
|
+
if line
|
24
|
+
@offset += line.length
|
25
|
+
end
|
26
|
+
return line
|
27
|
+
end
|
28
28
|
|
29
29
|
@read_size = [@read_size, @pos].min
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
@pos -= @read_size
|
31
|
+
@stream.seek(@pos, IO::SEEK_SET)
|
32
|
+
@offset = -@line_buffer.reduce(0) { |n,l| n + l.length }
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
34
|
+
@line_buffer[0] = "#{@stream.read(@read_size)}#{@line_buffer[0]}"
|
35
|
+
@line_buffer[0] = @line_buffer[0].scan(%r{.*\n})
|
36
|
+
@line_buffer.flatten!
|
37
37
|
|
38
|
-
|
39
|
-
|
38
|
+
readline
|
39
|
+
end
|
40
40
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
41
|
+
def sync
|
42
|
+
if @offset > 0
|
43
|
+
@stream.seek(-@offset, IO::SEEK_CUR)
|
44
|
+
end
|
45
|
+
@offset = 0
|
46
|
+
@stream
|
47
|
+
end
|
48
48
|
end
|
data/lib/tkellem/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tkellem
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.0
|
5
|
-
prerelease:
|
4
|
+
version: 0.9.0
|
5
|
+
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Brian Palmer
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-06-
|
12
|
+
date: 2013-06-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: eventmachine
|
@@ -179,13 +179,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
179
179
|
version: '0'
|
180
180
|
segments:
|
181
181
|
- 0
|
182
|
-
hash:
|
182
|
+
hash: 267049175566363735
|
183
183
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
184
184
|
none: false
|
185
185
|
requirements:
|
186
|
-
- - ! '
|
186
|
+
- - ! '>='
|
187
187
|
- !ruby/object:Gem::Version
|
188
|
-
version:
|
188
|
+
version: '0'
|
189
|
+
segments:
|
190
|
+
- 0
|
191
|
+
hash: 267049175566363735
|
189
192
|
requirements: []
|
190
193
|
rubyforge_project:
|
191
194
|
rubygems_version: 1.8.23
|