Class: Zstd::StreamReader

Inherits:
Object
  • Object
show all
Defined in:
lib/zstd-ruby/stream_reader.rb

Overview

TODO:

Exprimental

Instance Method Summary collapse

Constructor Details

#initialize(io) ⇒ StreamReader

Returns a new instance of StreamReader.



4
5
6
7
# File 'lib/zstd-ruby/stream_reader.rb', line 4

def initialize(io)
  @io = io
  @stream = Zstd::StreamingDecompress.new
end

Instance Method Details

#closeObject



17
18
19
20
# File 'lib/zstd-ruby/stream_reader.rb', line 17

def close
  @io.write(@stream.finish)
  @io.close
end

#read(length) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/zstd-ruby/stream_reader.rb', line 9

def read(length)
  if @io.eof?
    raise StandardError, "EOF"
  end
  data = @io.read(length)
  @stream.decompress(data)
end