Module: IOExtras::AbstractInputStream

Includes:
Enumerable, FakeIO
Included in:
Zip::NullInputStream, Zip::ZipInputStream
Defined in:
lib/zip/ioextras.rb

Overview

Implements many of the convenience methods of IO such as gets, getc, readline and readlines depends on: input_finished?, produce_input and read

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from FakeIO

#kind_of?

Methods included from Enumerable

#deep_clone, #deep_dup, #inject, #select_map

Instance Attribute Details

#linenoObject

Returns the value of attribute lineno.



21
22
23
# File 'lib/zip/ioextras.rb', line 21

def lineno
  @lineno
end

Instance Method Details

#each_line(aSepString = $/) ⇒ Object Also known as: each



58
59
60
61
62
63
# File 'lib/zip/ioextras.rb', line 58

def each_line(aSepString = $/)
  while true
	yield readline(aSepString)
  end
rescue EOFError
end

#flushObject



46
47
48
49
50
# File 'lib/zip/ioextras.rb', line 46

def flush
  retVal=@outputBuffer
  @outputBuffer=""
  return retVal
end

#gets(aSepString = $/) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/zip/ioextras.rb', line 29

def gets(aSepString=$/)
  @lineno = @lineno.next
  return read if aSepString == nil
  aSepString="#{$/}#{$/}" if aSepString == ""
  
  bufferIndex=0
  while ((matchIndex = @outputBuffer.index(aSepString, bufferIndex)) == nil)
	bufferIndex=@outputBuffer.length
	if input_finished?
	  return @outputBuffer.empty? ? nil : flush 
	end
	@outputBuffer << produce_input
  end
  sepIndex=matchIndex + aSepString.length
  return @outputBuffer.slice!(0...sepIndex)
end

#initializeObject



15
16
17
18
19
# File 'lib/zip/ioextras.rb', line 15

def initialize
  super
  @lineno = 0
  @outputBuffer = ""
end

#readline(aSepString = $/) ⇒ Object

Raises:

  • (EOFError)


52
53
54
55
56
# File 'lib/zip/ioextras.rb', line 52

def readline(aSepString = $/)
  retVal = gets(aSepString)
  raise EOFError if retVal == nil
  return retVal
end

#readlines(aSepString = $/) ⇒ Object



23
24
25
26
27
# File 'lib/zip/ioextras.rb', line 23

def readlines(aSepString = $/)
  retVal = []
  each_line(aSepString) { |line| retVal << line }
  return retVal
end