Class: Ciphr::Stream

Inherits:
Object
  • Object
show all
Defined in:
lib/ciphr/stream.rb

Instance Method Summary collapse

Constructor Details

#initialize(reader) ⇒ Stream

Returns a new instance of Stream.



3
4
5
6
7
# File 'lib/ciphr/stream.rb', line 3

def initialize(reader)
  @reader = reader
  @buffer = ""
  @eof = false
end

Instance Method Details

#prepend(str) ⇒ Object



31
32
33
# File 'lib/ciphr/stream.rb', line 31

def prepend(str)
  @buffer = str + @buffer
end

#read(n = nil) ⇒ Object

fix this



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ciphr/stream.rb', line 9

def read(n=nil) #fix this
  if n
    init
    while @buffer.size < n && !@eof 
      fill
    end
    if @buffer.size > 0
      ret = @buffer[0,n]
      @buffer = @buffer[n..-1] || ''
    else 
      ret = nil
    end
    ret
  else
    buff = ""
    while chunk=read(256)
      buff+=chunk
    end
    buff 
  end
end