Giter Club home page Giter Club logo

archiverb's Introduction

Archiverb provides Ruby bindings for creating [tar](http://en.wikipedia.org/wiki/Tar_(computing) and [ar](http://en.wikipedia.org/wiki/Ar_(Unix) archives in memory.

Install

gem install archiverb

Use

require "archiverb/ar"
require "archiverb/tar"

Adding files from the file system

archive  = Archiverb::Ar.new(File.expand_path("../henryIV.ar", __FILE__))
archive.add(File.expand_path("../spec/data/heneryIV.txt", __FILE__))
archive.add(File.expand_path("../spec/data/heneryIV-westmoreland.txt", __FILE__))

# archive will be written to henryIV.ar
archive.write 

Read an archive from the file system

archive  = Archiverb::Ar.new(File.expand_path("../henryIV.ar", __FILE__))
archive.read 

archive.names # => ["heneryIV.txt", "heneryIV-westmoreland.txt"] 
archive.files # => [#<Archiverb::File:0x007f8d7b90acf8 @name="heneryIV.txt" ... >, ...]

Adding files from memory

archive  = Archiverb::Ar.new(File.expand_path("../henryIV.ar", __FILE__))

contents = IO.read((File.expand_path("../spec/data/heneryIV.txt", __FILE__)))
archive.add("henryIV.txt", contents)

contents = IO.read((File.expand_path("../spec/data/heneryIV-westmoreland.txt", __FILE__)))
archive.add("henryIV-westmoreland.txt", contents)

archive.write 
archive  = Archiverb::Tar.new(File.expand_path("../henryIV.tar", __FILE__))

archive.add("data/", :mode => 0744)

contents = IO.read((File.expand_path("../spec/data/heneryIV.txt", __FILE__)))
archive.add("data/henryIV.txt", contents)

contents = IO.read((File.expand_path("../spec/data/heneryIV-westmoreland.txt", __FILE__)))
archive.add("data/henryIV-westmoreland.txt", contents)

archive.write 

Working with Gzip Files

Writing to a Gzip file

To create a gzipped tar archive, populate a Archiverb::Tar object in memory then create a GzipWriter object and pass it to Archiverb::Tar#write.

require "zlib"

path    = File.expand_path("../henryIV.tar", __FILE__)

archive = Archiverb::Tar.new
archive.add("data/henryIV.txt", 
            IO.read((File.expand_path("../spec/data/heneryIV.txt", __FILE__))))
archive.add("data/henryIV-westmoreland.txt", 
            IO.read((File.expand_path("../spec/data/heneryIV-westmoreland.txt", __FILE__))))

Zlib::GzipWriter.open(path) do |gz|
  archive.write(gz)
end

Reading from a Gzip file

require "zlib"

File.open(File.expand_path("../henryIV.tgz", __FILE__)) do |f|
  gz      = Zlib::GzipReader.new(f)
  archive = Archiverb::Tar.new(gz)
  archive.read
  archive.names # => ["data/henryIV.txt", "data/henryIV-westmoreland.txt"] 
end

archiverb's People

Contributors

gruis avatar

Watchers

 avatar  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.