Class: MappedFile
Instance Attribute Summary collapse
Instance Method Summary
collapse
#count_lines_upto, #parse_header
Constructor Details
#initialize(fname) ⇒ MappedFile
Returns a new instance of MappedFile.
164
165
166
167
168
169
170
171
172
173
174
175
176
|
# File 'lib/cless/data.rb', line 164
def initialize(fname)
@ptr = Mmap.new(fname)
@lines = nil
@file_path = fname
if block_given?
begin
yield(self)
ensure
munmap
end
end
end
|
Instance Attribute Details
#file_path ⇒ Object
Returns the value of attribute file_path.
162
163
164
|
# File 'lib/cless/data.rb', line 162
def file_path
@file_path
end
|
Instance Method Details
#[](*args) ⇒ Object
184
|
# File 'lib/cless/data.rb', line 184
def [](*args); @ptr[*args]; end
|
#each_line(&b) ⇒ Object
185
|
# File 'lib/cless/data.rb', line 185
def each_line(&b); @ptr.each_line(&b); end
|
#index(*args) ⇒ Object
181
|
# File 'lib/cless/data.rb', line 181
def index(*args); @ptr.index(*args); end
|
#lines ⇒ Object
188
189
190
191
192
193
|
# File 'lib/cless/data.rb', line 188
def lines
return @lines if @lines
@lines = @ptr.count("\n")
@lines += 1 if @ptr[-1] != ?\n
return @lines
end
|
#more_fd ⇒ Object
186
|
# File 'lib/cless/data.rb', line 186
def more_fd; nil; end
|
#munmap ⇒ Object
179
|
# File 'lib/cless/data.rb', line 179
def munmap; @ptr.munmap; end
|
#rindex(*args) ⇒ Object
180
|
# File 'lib/cless/data.rb', line 180
def rindex(*args); @ptr.rindex(*args); end
|
#search_index(*args) ⇒ Object
183
|
# File 'lib/cless/data.rb', line 183
def search_index(*args); index(*args); end
|
#search_rindex(*args) ⇒ Object
182
|
# File 'lib/cless/data.rb', line 182
def search_rindex(*args); rindex(*args); end
|
#size ⇒ Object
178
|
# File 'lib/cless/data.rb', line 178
def size; @ptr.size; end
|