ffi-libarchive

A Ruby FFI binding to libarchive.

This library provides Ruby FFI bindings to the well-known libarchive library.

Installation

Ensure that you have libarchive installed. On Debian/Ubuntu:

apt install libarchive13

On macOS with Homebrew:

brew install libarchive

Add this line to your application's Gemfile:

gem 'ffi-libarchive'

And then execute:

$ bundle

Or install it yourself as:

$ gem install ffi-libarchive

Usage

To extract an archive into the current directory:

flags = Archive::EXTRACT_PERM
reader = Archive::Reader.open_filename('/path/to/archive.tgz')

reader.each_entry do |entry|
  reader.extract(entry, flags.to_i)
end
reader.close

To create a gzipped tar archive:

Archive.write_open_filename('my.tgz', Archive::COMPRESSION_GZIP, Archive::FORMAT_TAR_PAX_RESTRICTED) do |tar|
  content = File.read 'some_path'
  size = content.size
  tar.new_entry do |e|
    e.pathname = 'some_path'
    e.size = size
    e.filetype = Archive::Entry::FILE
    tar.write_header e
    tar.write_data content
  end
end

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/chef/ffi-libarchive. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Community Guidelines code of conduct.

License

The gem is available as open source under the terms of the Apache License, v2