Class: RemoteRuby::StreamCacher

Inherits:
Object
  • Object
show all
Defined in:
lib/remote_ruby/stream_cacher.rb

Overview

Decorates the source stream and writes to the cache stream as the source is being read

Instance Method Summary collapse

Constructor Details

#initialize(source_stream, cache_stream) ⇒ StreamCacher

Returns a new instance of StreamCacher.


5
6
7
8
# File 'lib/remote_ruby/stream_cacher.rb', line 5

def initialize(source_stream, cache_stream)
  @source_stream = source_stream
  @cache_stream = cache_stream
end

Instance Method Details

#closeObject


26
27
28
# File 'lib/remote_ruby/stream_cacher.rb', line 26

def close
  source_stream.close
end

#eof?Boolean

Returns:

  • (Boolean)

22
23
24
# File 'lib/remote_ruby/stream_cacher.rb', line 22

def eof?
  source_stream.eof?
end

#read(*args) ⇒ Object


10
11
12
13
14
# File 'lib/remote_ruby/stream_cacher.rb', line 10

def read(*args)
  res = source_stream.read(*args)
  cache_stream.write(res)
  res
end

#readlineObject


16
17
18
19
20
# File 'lib/remote_ruby/stream_cacher.rb', line 16

def readline
  res = source_stream.readline
  cache_stream.write(res)
  res
end