Module: Rant::IOExtras::AbstractInputStream

Includes:
Enumerable, FakeIO
Included in:
Archive::Rubyzip::NullInputStream, Archive::Rubyzip::ZipInputStream
Defined in:
lib/rant/archive/rubyzip/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

#inject, #select_map

Instance Attribute Details

#linenoObject

Returns the value of attribute lineno.



28
29
30
# File 'lib/rant/archive/rubyzip/ioextras.rb', line 28

def lineno
  @lineno
end

Instance Method Details

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



65
66
67
68
69
70
# File 'lib/rant/archive/rubyzip/ioextras.rb', line 65

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

#flushObject



53
54
55
56
57
# File 'lib/rant/archive/rubyzip/ioextras.rb', line 53

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

#gets(aSepString = $/) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/rant/archive/rubyzip/ioextras.rb', line 36

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



22
23
24
25
26
# File 'lib/rant/archive/rubyzip/ioextras.rb', line 22

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

#readline(aSepString = $/) ⇒ Object

Raises:

  • (EOFError)


59
60
61
62
63
# File 'lib/rant/archive/rubyzip/ioextras.rb', line 59

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

#readlines(aSepString = $/) ⇒ Object



30
31
32
33
34
# File 'lib/rant/archive/rubyzip/ioextras.rb', line 30

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