Method: Kaitai::Struct::Stream#read_bytes_term

Defined in:
lib/kaitai/struct/struct.rb

#read_bytes_term(term, include_term, consume_term, eos_error) ⇒ Object



390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
# File 'lib/kaitai/struct/struct.rb', line 390

def read_bytes_term(term, include_term, consume_term, eos_error)
  term_byte = term.chr
  r = String.new
  loop {
    c = @_io.getc
    if c.nil?
      if eos_error
        raise EOFError.new("end of stream reached, but no terminator #{term} found")
      end

      return r
    end
    if c == term_byte
      r << c if include_term
      @_io.seek(@_io.pos - 1) unless consume_term
      return r
    end
    r << c
  }
end