Method: FlatKit::Jsonl::Writer#write_record

Defined in:
lib/flat_kit/jsonl/writer.rb

#write_record(record) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/flat_kit/jsonl/writer.rb', line 31

def write_record(record)
  # the index of the record being written is the same as the count of records written so far
  record_index = @count

  # get the current output stream position to calculate bytes written
  start_offset = output.io.tell

  # enforces ending in newline if it doesn't already have one
  output.io.puts record.to_s

  ending_offset = output.io.tell
  bytes_written = (ending_offset - start_offset)

  @count += 1

  @last_position = ::FlatKit::Position.new(index: record_index,
                                           offset: start_offset,
                                           bytesize: bytes_written)
end