Class: CPEE::Logging::HeaderAndFile

Inherits:
Object
  • Object
show all
Defined in:
lib/cpee-logging-xes-yaml/implementation.rb

Overview

}}}

Instance Method Summary collapse

Constructor Details

#initialize(header, io) ⇒ HeaderAndFile

{{{



72
73
74
75
76
# File 'lib/cpee-logging-xes-yaml/implementation.rb', line 72

def initialize(header, io)
  @header = header
  @io = io
  @position = 0
end

Instance Method Details

#closeObject



99
100
101
102
# File 'lib/cpee-logging-xes-yaml/implementation.rb', line 99

def close
  @io&.close
  @io = nil
end

#read(length = nil, outbuf = nil) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/cpee-logging-xes-yaml/implementation.rb', line 78

def read(length = nil, outbuf = nil)
  if @position < @header.bytesize
    data = read_header(length)

    if length && data.bytesize < length
      remaining_length = length - data.bytesize
      file_data = @io.read
      data << file_data if file_data
    end
  else
    data = @io.read(length)
  end

  return data.nil? || data.empty? && length ? nil : append_to_outbuf(data, outbuf)
end

#rewindObject



94
95
96
97
# File 'lib/cpee-logging-xes-yaml/implementation.rb', line 94

def rewind
  @io&.rewind
  @position = 0 # returning position is the way rewind does it
end