Module: LZMA::Aux

Defined in:
lib/extlzma2/aux.rb

Class Method Summary collapse

Class Method Details

.decode(src, decoder) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/extlzma2/aux.rb', line 25

def self.decode(src, decoder)
  return decode(StringIO.new(src), decoder, &:read) if src.is_a?(String)

  s = Decoder.new(decoder, src)
  return s unless block_given?

  begin
    yield(s)
  ensure
    begin
      s.close
    rescue StandardError
      nil
    end
  end
end

.encode(src, encoder) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/extlzma2/aux.rb', line 7

def self.encode(src, encoder)
  if src.is_a?(String)
    s = Encoder.new(encoder, String.new)
    s << src
    s.close
    return s.outport
  end

  s = Encoder.new(encoder, (src || String.new))
  return s unless block_given?

  begin
    yield(s)
  ensure
    s.close
  end
end