Class: Archive::BaseArchive Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/ffi_libarchive/archive.rb

Overview

This class is abstract.

Direct Known Subclasses

Reader, Writer

Instance Method Summary collapse

Constructor Details

#initialize(alloc, free) ⇒ BaseArchive

Returns a new instance of BaseArchive.

Parameters:

  • alloc (Method)
  • free (Method)

Raises:

  • (ArgumentError)


150
151
152
153
154
155
156
157
158
# File 'lib/ffi_libarchive/archive.rb', line 150

def initialize(alloc, free)
  raise ArgumentError, 'Invalid methods' unless alloc.respond_to?(:call) && free.respond_to?(:call)

  @archive = alloc.call
  raise Error, 'No archive open' unless @archive

  @archive_free = [free]
  ObjectSpace.define_finalizer(self, method(:close).to_proc)
end

Instance Method Details

#closeObject



160
161
162
163
164
165
166
# File 'lib/ffi_libarchive/archive.rb', line 160

def close
  # TODO: do we need synchronization here?
  @archive_free[0].call(@archive) if @archive && @archive_free[0].respond_to?(:call) # TODO: Error check?
ensure
  @archive         = nil
  @archive_free[0] = nil
end

#errnoInteger

Returns:

  • (Integer)


178
179
180
# File 'lib/ffi_libarchive/archive.rb', line 178

def errno
  C.archive_errno(archive)
end

#error_stringString

Returns:

  • (String)


173
174
175
# File 'lib/ffi_libarchive/archive.rb', line 173

def error_string
  C.archive_error_string(archive)
end