Class: Archive::BaseArchive

Inherits:
Object
  • Object
show all
Defined in:
lib/ffi-libarchive/archive.rb

Direct Known Subclasses

Reader, Writer

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(alloc, free) ⇒ BaseArchive

Returns a new instance of BaseArchive.

Raises:



332
333
334
335
336
337
338
339
340
341
# File 'lib/ffi-libarchive/archive.rb', line 332

def initialize(alloc, free)
  @archive = nil
  @archive_free = nil
  @archive = alloc.call
  @archive_free = [nil]
  raise Error, @archive unless @archive

  @archive_free[0] = free
  ObjectSpace.define_finalizer(self, BaseArchive.finalizer(@archive, @archive_free))
end

Class Method Details

.finalizer(archive, archive_free) ⇒ Object



343
344
345
346
347
# File 'lib/ffi-libarchive/archive.rb', line 343

def self.finalizer(archive, archive_free)
  proc do |*_args|
    archive_free[0].call(archive) if archive_free[0]
  end
end

Instance Method Details

#closeObject



349
350
351
352
353
354
355
356
357
358
359
# File 'lib/ffi-libarchive/archive.rb', line 349

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

#compressionObject



368
369
370
# File 'lib/ffi-libarchive/archive.rb', line 368

def compression
  C.archive_compression(@archive)
end

#compression_nameObject



372
373
374
# File 'lib/ffi-libarchive/archive.rb', line 372

def compression_name
  C.archive_compression_name(@archive)
end

#errnoObject



380
381
382
# File 'lib/ffi-libarchive/archive.rb', line 380

def errno
  C.archive_errno(@archive)
end

#error_stringObject



376
377
378
# File 'lib/ffi-libarchive/archive.rb', line 376

def error_string
  C.archive_error_string(@archive)
end

#formatObject



384
385
386
# File 'lib/ffi-libarchive/archive.rb', line 384

def format
  C.archive_format(@archive)
end

#format_nameObject



388
389
390
# File 'lib/ffi-libarchive/archive.rb', line 388

def format_name
  C.archive_format_name(@archive)
end