Class: Bzip2::FFI::IO

Inherits:
Object
  • Object
show all
Defined in:
lib/bzip2/ffi/io.rb

Overview

IO is a base class providing common functionality for the Reader and Writer subclasses.

Holds a reference to an underlying IO-like stream representing the bzip2 compressed data to be read from or written to.

Direct Known Subclasses

Reader, Writer

Instance Method Summary collapse

Instance Method Details

#autoclose=(autoclose) ⇒ Object

Sets whether the underlying compressed IO-like instance should be closed when #close is called (true) or left open (false).

Parameters:

  • autoclose (Boolean)

    true if the underlying compressed IO instance should be closed when #close is called, or false if it should be left open.

Raises:



109
110
111
112
# File 'lib/bzip2/ffi/io.rb', line 109

def autoclose=(autoclose)
  check_closed
  @autoclose = !!autoclose
end

#autoclose?Boolean

Returns true if the underlying compressed IO-like instance will be closed when #close is called, otherwise false.

Returns:

  • (Boolean)

    true if the underlying compressed IO-like instance will be closed when #close is closed, otherwise false.

Raises:



97
98
99
100
# File 'lib/bzip2/ffi/io.rb', line 97

def autoclose?
  check_closed
  @autoclose
end

#binmodeIO

Puts the Bzip2::FFI::IO instance into binary mode.

Note that Bzip2::FFI::IO and subclasses always operate in binary mode, so calling binmode has no effect.

Returns:

  • (IO)

    self.

Raises:



131
132
133
134
# File 'lib/bzip2/ffi/io.rb', line 131

def binmode
  check_closed
  self
end

#binmode?Boolean

Returns true to indicate that the Bzip2::FFI::IO instance is operating in binary mode (as is always the case).

Returns:

  • (Boolean)

    true.

Raises:



119
120
121
122
# File 'lib/bzip2/ffi/io.rb', line 119

def binmode?
  check_closed
  true
end

#closeNilClass

Closes the Bzip2::FFI::IO instance.

If #autoclose? is true and the underlying compressed IO-like instance responds to close, it will also be closed.

Returns:

  • (NilClass)

    nil.

Raises:

  • (IOError)

    If the Bzip2::FFI::IO instance has already been closed.



143
144
145
146
147
# File 'lib/bzip2/ffi/io.rb', line 143

def close
  check_closed
  @io.close if autoclose? && @io.respond_to?(:close)
  @stream = nil
end

#closed?Boolean

Indicates whether the Bzip2::FFI::IO instance has been closed by calling #close.

Returns:

  • (Boolean)

    true if the Bzip2::FFI::IO instance has been closed, otherwise false.



153
154
155
# File 'lib/bzip2/ffi/io.rb', line 153

def closed?
  !@stream
end

#external_encodingEncoding

Returns the Encoding object that represents the encoding of data prior to being compressed or after being decompressed.

No character conversion is performed, so external_encoding always returns Encoding::ASCII_8BIT (also known as Encoding::BINARY).

Returns:

  • (Encoding)

    Encoding::ASCII_8BIT.

Raises:



165
166
167
168
# File 'lib/bzip2/ffi/io.rb', line 165

def external_encoding
  check_closed
  Encoding::ASCII_8BIT
end

#internal_encodingEncoding

The internal encoding for character conversions.

No character conversion is performed, so internal_encoding always returns Encoding::ASCII_8BIT (also known as Encoding::BINARY).

Returns:

  • (Encoding)

    Encoding::ASCII_8BIT.

Raises:

  • (IOError)

    If the IO has been closed.



177
178
179
180
# File 'lib/bzip2/ffi/io.rb', line 177

def internal_encoding
  check_closed
  Encoding::ASCII_8BIT
end