Class: Fairy::InputLocalFile::SplittedFile
- Inherits:
-
Object
- Object
- Fairy::InputLocalFile::SplittedFile
- Includes:
- Enumerable
- Defined in:
- lib/fairy/client/input-local-file.rb
Overview
def split_opens(split_size, &block)
begin
seek = 0 size = File.stat(@filename).size while seek < size io = SplittedFile.open(@filename, seek, seek + split_size) seek = io.seek_end + 1 yield io end
rescue
Log::warn_exception(self) raise
end
end
Instance Attribute Summary collapse
-
#seek_end ⇒ Object
readonly
Returns the value of attribute seek_end.
-
#seek_start ⇒ Object
readonly
Returns the value of attribute seek_start.
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
- #each(&block) ⇒ Object
- #external_encoding ⇒ Object
-
#initialize(fd, seek_start, seek_end) ⇒ SplittedFile
constructor
A new instance of SplittedFile.
- #read(length) ⇒ Object
Constructor Details
#initialize(fd, seek_start, seek_end) ⇒ SplittedFile
Returns a new instance of SplittedFile.
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/fairy/client/input-local-file.rb', line 137 def initialize(fd, seek_start, seek_end) @io = File.open(fd) @seek_start = seek_start @io.seek(seek_end) c = @io.read(1) case c when nil, "\n" @seek_end = seek_end else @io.gets @seek_end = @io.pos - 1 end @io.seek(seek_start) end |
Instance Attribute Details
#seek_end ⇒ Object (readonly)
Returns the value of attribute seek_end.
154 155 156 |
# File 'lib/fairy/client/input-local-file.rb', line 154 def seek_end @seek_end end |
#seek_start ⇒ Object (readonly)
Returns the value of attribute seek_start.
153 154 155 |
# File 'lib/fairy/client/input-local-file.rb', line 153 def seek_start @seek_start end |
Class Method Details
.open(fd, seek_start, seek_end, &block) ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/fairy/client/input-local-file.rb', line 124 def self.open(fd, seek_start, seek_end, &block) sf = new(fd, seek_start, seek_end) if block_given? begin yield sf ensure sf.close end else sf end end |
Instance Method Details
#close ⇒ Object
160 161 162 163 |
# File 'lib/fairy/client/input-local-file.rb', line 160 def close @io.close @io = nil end |
#each(&block) ⇒ Object
165 166 167 168 169 170 171 172 173 174 |
# File 'lib/fairy/client/input-local-file.rb', line 165 def each(&block) begin while @io.pos < @seek_end && l = @io.gets yield l end rescue Log::warn_exception(self) raise end end |
#external_encoding ⇒ Object
156 157 158 |
# File 'lib/fairy/client/input-local-file.rb', line 156 def external_encoding @io.external_encoding end |
#read(length) ⇒ Object
176 177 178 179 180 181 182 183 184 185 |
# File 'lib/fairy/client/input-local-file.rb', line 176 def read(length) if @seek_end - @io.pos + 1 < length length = @seek_end - @io.pos + 1 end if length == 0 nil else @io.read(length) end end |