Class: ArrowFormat::StreamingReader

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/arrow-format/streaming-reader.rb

Instance Method Summary collapse

Constructor Details

#initialize(input) ⇒ StreamingReader

Returns a new instance of StreamingReader.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/arrow-format/streaming-reader.rb', line 24

def initialize(input)
  case input
  when File
    @input = IO::Buffer.map(input, nil, 0, IO::Buffer::READONLY)
    @offset = 0
  when String
    @input = IO::Buffer.for(input)
    @offset = 0
  else
    @input = input
  end

  @on_read = nil
  @pull_reader = StreamingPullReader.new do |record_batch|
    @on_read.call(record_batch) if @on_read
  end
  @buffer = "".b
  ensure_schema
end

Instance Method Details

#each(&block) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/arrow-format/streaming-reader.rb', line 48

def each(&block)
  return to_enum(__method__) unless block_given?

  @on_read = block
  begin
    loop do
      break unless consume
    end
  ensure
    @on_read = nil
  end
end

#schemaObject



44
45
46
# File 'lib/arrow-format/streaming-reader.rb', line 44

def schema
  @pull_reader.schema
end