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

Returns a new instance of HeaderAndFile.



31
32
33
34
35
# File 'lib/cpee-logging-xes-yaml/implementation.rb', line 31

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

Instance Method Details

#closeObject



58
59
60
61
# File 'lib/cpee-logging-xes-yaml/implementation.rb', line 58

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

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



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/cpee-logging-xes-yaml/implementation.rb', line 37

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



53
54
55
56
# File 'lib/cpee-logging-xes-yaml/implementation.rb', line 53

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