archive-ar 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/.gitignore +17 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/archive-ar.gemspec +23 -0
- data/lib/archive/ar.rb +22 -0
- data/lib/archive/ar/format.rb +28 -0
- data/lib/archive/ar/reader.rb +47 -0
- data/lib/archive/ar/version.rb +5 -0
- data/lib/archive/ar/writer.rb +12 -0
- data/spec/fixtures/test.ar +13 -0
- data/spec/lib/archive/ar/format_spec.rb +41 -0
- data/spec/lib/archive/ar/reader_spec.rb +41 -0
- data/spec/lib/archive/ar_spec.rb +0 -0
- data/spec/spec_helper.rb +1 -0
- metadata +108 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YjgxYzllNThiOWViMDliZmNkZWZlZjQ4MGE1MjQ5MWIyODVlMmM2NA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
OWE3MjlkMzJmNDUzYjIzN2VkOTU4Zjk3MGNiMDczYzIxOGZlYjYxNw==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZTRiZjBiNmZjMjU3NDlhY2Y0MGZkMmIzMzRlNzc1OWMwOWE0ZTMzMWZhZjgx
|
10
|
+
MzAzYzI3YWUxNWU1NzVlYTNhMjNmNTQzNTAzYzIxZDIwMmUxMzM5ZTQ4Njgx
|
11
|
+
MzBjNzUyYmZiYzZlN2Y1NDJmOGE0YWY0NTkzNWNhZDYyM2NkMmQ=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YTFlMGI3ODhlZTAxNmVjOGU3OWQ0OWU3ZDZiZWI0Zjk3NjY4NTA0NzAzMmQy
|
14
|
+
YzVhN2QwNmQ5ZmM5NmM5MjRkY2FlY2EyODgyOWI0NmQ5ZWJhNjQ5Mjg2YmE0
|
15
|
+
N2E5MGRkNzk1ZmY0YzE2YWU3ZGZlMDBiZDYyNDI2OTYxMjA0YTg=
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color --format doc
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Joshua B. Bussdieker
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Archive::Ar
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'archive-ar'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install archive-ar
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( http://github.com/<my-github-username>/archive-ar/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/archive-ar.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'archive/ar/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "archive-ar"
|
8
|
+
spec.version = Archive::Ar::VERSION
|
9
|
+
spec.authors = ["Joshua B. Bussdieker"]
|
10
|
+
spec.email = ["jbussdieker@gmail.com"]
|
11
|
+
spec.summary = %q{Simple AR file functions}
|
12
|
+
spec.homepage = ""
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
spec.add_development_dependency "rspec"
|
23
|
+
end
|
data/lib/archive/ar.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require "archive/ar/version"
|
2
|
+
require "archive/ar/format"
|
3
|
+
require "archive/ar/reader"
|
4
|
+
require "archive/ar/writer"
|
5
|
+
|
6
|
+
module Archive
|
7
|
+
module Ar
|
8
|
+
MAGIC = "!<arch>\n"
|
9
|
+
|
10
|
+
def self.create(dest_file, filenames = [], options = {})
|
11
|
+
Writer.new(filenames).write(dest_file, options)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.extract(source_file, dest_dir, options = {})
|
15
|
+
Reader.new(source_file, options).extract(dest_dir, options)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.traverse(source_file, options = {}, &block)
|
19
|
+
Reader.new(source_file, options).each(&block)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Archive
|
2
|
+
module Ar
|
3
|
+
class Format
|
4
|
+
class << self
|
5
|
+
def read_global_header(io)
|
6
|
+
io.read(8).tap do |global_header|
|
7
|
+
raise "Invalid header" unless global_header == Archive::Ar::MAGIC
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def read_header(io)
|
12
|
+
block = io.read(60)
|
13
|
+
h = block.unpack("A16 Z12 a6 a6 A8 Z10 Z2")
|
14
|
+
{
|
15
|
+
:name => h.shift,
|
16
|
+
:modified => Time.at(h.shift.to_i),
|
17
|
+
:owner => h.shift.to_i,
|
18
|
+
:group => h.shift.to_i,
|
19
|
+
:mode => h.shift,
|
20
|
+
:start => io.tell,
|
21
|
+
:size => h.shift.to_i,
|
22
|
+
:magic => h.shift,
|
23
|
+
}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Archive
|
2
|
+
module Ar
|
3
|
+
class Reader
|
4
|
+
def initialize(source, options)
|
5
|
+
@source = source
|
6
|
+
@options = options
|
7
|
+
end
|
8
|
+
|
9
|
+
def extract(dest_dir, options)
|
10
|
+
end
|
11
|
+
|
12
|
+
def each(full = false, &block)
|
13
|
+
case @source
|
14
|
+
when IO
|
15
|
+
parse(@source, full); @source.rewind
|
16
|
+
else
|
17
|
+
File.open(@source, 'r') { |f| parse(f, full) }
|
18
|
+
end
|
19
|
+
|
20
|
+
@index.each { |path| yield *(@records[path]) }
|
21
|
+
end
|
22
|
+
|
23
|
+
def parse(io, full = false)
|
24
|
+
@index = []
|
25
|
+
@records = {}
|
26
|
+
|
27
|
+
Archive::Ar::Format.read_global_header(io)
|
28
|
+
|
29
|
+
until io.eof?
|
30
|
+
header = Archive::Ar::Format.read_header(io)
|
31
|
+
size = header[:size]
|
32
|
+
name = header[:name]
|
33
|
+
|
34
|
+
@index << name
|
35
|
+
@records[name] = [header, io.read(size)]
|
36
|
+
|
37
|
+
# Data sections are 2 byte aligned
|
38
|
+
if size % 2 == 1
|
39
|
+
io.read(1)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
@records
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
!<arch>
|
2
|
+
Gemfile 1399095295 501 20 100644 95 `
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
( Specify your gem's dependencies in archive-ar.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
Semfile 1399095295 502 20 100644 95 `
|
9
|
+
source 'https://rubygems.org'
|
10
|
+
|
11
|
+
# Specify your gem's dependencies in archive-ar.gemspec
|
12
|
+
gemspec
|
13
|
+
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Archive::Ar::Format do
|
4
|
+
describe "read_global_header" do
|
5
|
+
let(:read_global_header) { Archive::Ar::Format.read_global_header(io) }
|
6
|
+
subject { read_global_header }
|
7
|
+
|
8
|
+
context "when valid" do
|
9
|
+
let(:io) { StringIO.new("!<arch>\n") }
|
10
|
+
|
11
|
+
it { should == "!<arch>\n" }
|
12
|
+
end
|
13
|
+
|
14
|
+
context "when invalid" do
|
15
|
+
let(:io) { StringIO.new("") }
|
16
|
+
|
17
|
+
it "should raise exception" do
|
18
|
+
expect { subject }.to raise_error
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "read_header" do
|
24
|
+
let(:read_header) { Archive::Ar::Format.read_header(io) }
|
25
|
+
let(:io) { StringIO.new("Filename 1399095295 1234 5678 100644 95 `\n") }
|
26
|
+
subject { read_header }
|
27
|
+
|
28
|
+
it {
|
29
|
+
subject.should == {
|
30
|
+
:name=>"Filename",
|
31
|
+
:modified=>Time.parse("2014-05-02 22:34:55 -0700"),
|
32
|
+
:owner=>1234,
|
33
|
+
:group=>5678,
|
34
|
+
:mode=>"100644",
|
35
|
+
:start=>60,
|
36
|
+
:size=>95,
|
37
|
+
:magic=>"`\n"
|
38
|
+
}
|
39
|
+
}
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Archive::Ar::Reader do
|
4
|
+
let(:source) { File.open("spec/fixtures/test.ar") }
|
5
|
+
let(:reader) { Archive::Ar::Reader.new(source, {}) }
|
6
|
+
|
7
|
+
describe "parse" do
|
8
|
+
let(:source) { io }
|
9
|
+
let(:options) { {} }
|
10
|
+
let(:reader) { Archive::Ar::Reader.new(source, options) }
|
11
|
+
subject { reader.parse(io) }
|
12
|
+
|
13
|
+
context "empty" do
|
14
|
+
let(:io) { StringIO.new("") }
|
15
|
+
it "should raise exception" do
|
16
|
+
expect { subject }.to raise_error
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "global header only" do
|
21
|
+
let(:io) { StringIO.new("!<arch>\n") }
|
22
|
+
it { should == {} }
|
23
|
+
end
|
24
|
+
|
25
|
+
context "one file" do
|
26
|
+
let(:io) { StringIO.new("!<arch>\nGemfile 1399095295 501 20 100644 95 `\nASDF") }
|
27
|
+
it {
|
28
|
+
should == { "Gemfile" => [{
|
29
|
+
name: "Gemfile",
|
30
|
+
modified: Time.at(1399095295),
|
31
|
+
owner: 501,
|
32
|
+
group: 20,
|
33
|
+
mode: "100644",
|
34
|
+
start: 68,
|
35
|
+
size: 95,
|
36
|
+
magic: "`\n",
|
37
|
+
}, "ASDF"]}
|
38
|
+
}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
File without changes
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'archive/ar'
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: archive-ar
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Joshua B. Bussdieker
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- jbussdieker@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- .rspec
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- archive-ar.gemspec
|
69
|
+
- lib/archive/ar.rb
|
70
|
+
- lib/archive/ar/format.rb
|
71
|
+
- lib/archive/ar/reader.rb
|
72
|
+
- lib/archive/ar/version.rb
|
73
|
+
- lib/archive/ar/writer.rb
|
74
|
+
- spec/fixtures/test.ar
|
75
|
+
- spec/lib/archive/ar/format_spec.rb
|
76
|
+
- spec/lib/archive/ar/reader_spec.rb
|
77
|
+
- spec/lib/archive/ar_spec.rb
|
78
|
+
- spec/spec_helper.rb
|
79
|
+
homepage: ''
|
80
|
+
licenses:
|
81
|
+
- MIT
|
82
|
+
metadata: {}
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ! '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 2.2.2
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: Simple AR file functions
|
103
|
+
test_files:
|
104
|
+
- spec/fixtures/test.ar
|
105
|
+
- spec/lib/archive/ar/format_spec.rb
|
106
|
+
- spec/lib/archive/ar/reader_spec.rb
|
107
|
+
- spec/lib/archive/ar_spec.rb
|
108
|
+
- spec/spec_helper.rb
|