GithubHelp home page GithubHelp logo

isabella232 / libarchive-ruby-swig Goto Github PK

View Code? Open in Web Editor NEW

This project forked from computology/libarchive-ruby-swig

0.0 0.0 0.0 96 KB

Ruby bindings to libarchive using SWIG

Home Page: libarchive-rs.rubyforge.org

License: Other

Ruby 37.22% C++ 62.78%

libarchive-ruby-swig's Introduction

= libarchive-ruby-swig

Copyright (c) 2011, Tobias Koch <[email protected]>

= Description

Ruby bindings to libarchive allowing reading and creation of compressed archive
files of various formats. This gem uses {SWIG}[http://swig.org] to generate the
bindings from a C++ wrapper around libarchive. It is mostly interface-compatible
with the {Libarchive/Ruby}[https://bitbucket.org/winebarrel/libarchive-ruby/]
gem by Sugawara Genki.

= Installation

Install the gem 

 gem install libarchive-ruby-swig

or clone the git source repository

 git clone git://github.com/tobijk/libarchive-ruby-swig.git

and then build and install

 gem build libarchive-ruby-swig.gemspec
 gem install libarchive-ruby-swig-<version>.gem

Please mind that you need to install SWIG and the development files for libarchive in order to compile the native extension.


= Usage Examples

== Writing an Archive

The following example shows how to recursively pack everything from the current
working directory into a bzip2-compressed tarball:

  require 'libarchive_rs'

  Archive.write_open_filename('../test.tar.bz2', Archive::COMPRESSION_BZIP2, Archive::FORMAT_TAR) do |ar|
    Dir.glob('**/*').each do |fn|
      ar.new_entry do |entry|
        entry.copy_stat(fn)
        entry.pathname = fn
        ar.write_header(entry)

        if entry.file?
          open(fn) do |f|
            ar.write_data { f.read(1024) }
          end
        end

      end
    end
  end


== Reading from an Archive

The following example shows how to extract all files from the given archive to
the current working directory:

  require 'libarchive_rs'

  Archive.read_open_filename(filename) do |archive|
    while entry = archive.next_header
      path = entry.pathname.sub(/^\//, '')
      if entry.directory?
        Dir.mkdir path unless File.directory? path
      elsif entry.symbolic_link?
        File.symlink(entry.symlink, path)
      else
        File.open(path, 'w+') do |fp|
          archive.read_data(1024) {|data| fp.write(data)}
        end
      end
      File.chmod(entry.mode, path) unless entry.symbolic_link?
    end
  end

Note that this example doesn't treat special entries, such as device nodes, correctly.

libarchive-ruby-swig's People

Contributors

capotej avatar ice799 avatar tobijk avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.