Module: Zip::IOExtras::FakeIO

Included in:
AbstractInputStream, AbstractOutputStream
Defined in:
lib/zip/ioextras/fake_io.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#external_encodingObject (readonly)

Returns the value of attribute external_encoding.



6
7
8
# File 'lib/zip/ioextras/fake_io.rb', line 6

def external_encoding
  @external_encoding
end

#internal_encodingObject (readonly)

Returns the value of attribute internal_encoding.



6
7
8
# File 'lib/zip/ioextras/fake_io.rb', line 6

def internal_encoding
  @internal_encoding
end

Instance Method Details

#initialize(**opts) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/zip/ioextras/fake_io.rb', line 8

def initialize(**opts)
  @internal_encoding = Encoding.find(opts[:internal_encoding]) if opts[:internal_encoding]

  if opts[:encoding].kind_of?(String)
    _ext, int = opts[:encoding].split(':', 2)
    @internal_encoding = Encoding.find(int) unless @internal_encoding || int.nil?
  end

  @external_encoding = Encoding::ASCII_8BIT
end

#kind_of?(object) ⇒ Boolean

Implement kind_of? in order to pretend to be an IO object.

Returns:

  • (Boolean)


34
35
36
# File 'lib/zip/ioextras/fake_io.rb', line 34

def kind_of?(object)
  object == IO || super
end

#set_encoding(ext_enc, int_enc = nil) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/zip/ioextras/fake_io.rb', line 19

def set_encoding(ext_enc, int_enc = nil)
  if ext_enc.kind_of?(String) && ext_enc.include?(':')
    _ext_enc, int_enc = ext_enc.split(':', 2)
  end

  begin
    @internal_encoding = Encoding.find(int_enc) if int_enc
  rescue ArgumentError
    warn "warning: Unsupported encoding #{int_enc} ignored"
  end

  @external_encoding = Encoding::ASCII_8BIT
end