[ruby-list:45793] [ANN] Libarchive/Ruby 0.1.0

From: SUGAWARA Genki <sgwr_dts@...>
Date: 2009-01-06 17:00:58 UTC
List: ruby-list #45793
すがわらといいます。

Libarchive/Ruby 0.1.0をリリースしました。

http://libarchive.rubyforge.org/

Libarchive/Rubyは、tar等のアーカイブの作成・読み込みを行うライブラリ 
Libarchive(http://people.freebsd.org/~kientzle/libarchive/)のラッパーです。

まだ十分にテストできていませんが、興味があればお試しください。

== Example
=== reading archive
    require 'libarchive_ruby'
    
    Archive::Reader.open_filename('foo.tar.gz') do |ar|
      while entry = ar.next_header
        name = entry.pathname
        data = ar.read_data
    
        #data = ""
        #ar.read_data(1024) do |x|
        #  data << x
        #end
    
        puts "#{name} (size=#{data.size})"
      end
    end

=== creating archive
    require 'libarchive_ruby'
    
    Archive::Writer.open_filename('foo.tar.bz2', COMPRESSION_BZIP2, FORMAT_TAR_USTAR) do |ar|
      Dir.glob('*.c').each do |fn|
        ar.new_entry do |entry|
          entry.copy_stat(fn)
          entry.pathname = fn
          ar.write_header(entry)
          ar.write_data(open(fn) {|f| f.read })
    
          #open(fn) do |f|
          #  ar.write_data do
          #    f.read(1024)
          #  end
          #end
        end
      end
    end

-- 
SUGAWARA Genki <sgwr_dts@yahoo.co.jp>

--------------------------------------
Power up the Internet with Yahoo! Toolbar.
http://pr.mail.yahoo.co.jp/toolbar/

In This Thread

Prev Next