class FBO::ChunkedFile

Constants

DEFAULT_CHUNK_SIZE

Attributes

chunk_size[R]
file[R]

Public Class Methods

new(file, chunk_size = DEFAULT_CHUNK_SIZE) click to toggle source
# File lib/fbo/chunked_file.rb, line 14
def initialize(file, chunk_size = DEFAULT_CHUNK_SIZE)
  @file = file
  @chunk_size = chunk_size
end

Public Instance Methods

contents() click to toggle source
# File lib/fbo/chunked_file.rb, line 19
def contents
  if @contents.nil?
    @contents = []
    while !eof
      @contents << next_chunk
    end
    @contents.compact!
  end
  @contents
end

Private Instance Methods

next_chunk() click to toggle source
# File lib/fbo/chunked_file.rb, line 33
def next_chunk
  return nil if eof

  chunk, line = "", ""

  # Run up the chunk to about #chunk_size.
  begin
    line = gets
    break unless line
    chunk += line
  end while (chunk.bytesize < @chunk_size && !eof)

  # Add lines up to the end of a notice.
  if line && line !~ FBO::NOTICE_CLOSE_REGEXP
    begin
      line = gets
      break unless line
      chunk += line
      break if line =~ FBO::NOTICE_CLOSE_REGEXP
    end while (!eof)
  end

  return chunk.strip
end