archive-ar 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YjgxYzllNThiOWViMDliZmNkZWZlZjQ4MGE1MjQ5MWIyODVlMmM2NA==
4
+ NmEwMzBjZGVmZTJmOTJlN2VmMjc5ZDI5ZDA1ODQ4MTE2YTA5MzdmYg==
5
5
  data.tar.gz: !binary |-
6
- OWE3MjlkMzJmNDUzYjIzN2VkOTU4Zjk3MGNiMDczYzIxOGZlYjYxNw==
6
+ M2VhYmEzNWRhYTFjMWEyNTFhMzQyZjljNzEzOTljNTE1MDQwZmVjNg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZTRiZjBiNmZjMjU3NDlhY2Y0MGZkMmIzMzRlNzc1OWMwOWE0ZTMzMWZhZjgx
10
- MzAzYzI3YWUxNWU1NzVlYTNhMjNmNTQzNTAzYzIxZDIwMmUxMzM5ZTQ4Njgx
11
- MzBjNzUyYmZiYzZlN2Y1NDJmOGE0YWY0NTkzNWNhZDYyM2NkMmQ=
9
+ N2YyNTk2NTU3OTlhMzliMWRhNjYxMGU3NTJiYjYwZmIxNmE5ZTg4OTUxN2Zj
10
+ ZWFkMTBmZmJlYzBhNzlhZjg4NjRhMjE4NWVlNWY3Y2FhODhmYTdlOGQ4MmMz
11
+ MDgwNGMyNjkyM2M5MTAyZjg3NTNlYTkzZGJiODQ1NDBiMDA4ZWU=
12
12
  data.tar.gz: !binary |-
13
- YTFlMGI3ODhlZTAxNmVjOGU3OWQ0OWU3ZDZiZWI0Zjk3NjY4NTA0NzAzMmQy
14
- YzVhN2QwNmQ5ZmM5NmM5MjRkY2FlY2EyODgyOWI0NmQ5ZWJhNjQ5Mjg2YmE0
15
- N2E5MGRkNzk1ZmY0YzE2YWU3ZGZlMDBiZDYyNDI2OTYxMjA0YTg=
13
+ MTVhMmU2YTQ5ZmIxNTBhM2MxYWViZjI3MjNjMDU1ZTIyNDY4MjBmZDk5YWMy
14
+ OTQ4MTc1YjI5ODRkZjA3ZDM2OTQ1ZDJmYmY4NDFkYmQ4MzMyMDZkNTc1MTQ2
15
+ NjYzY2FkZDY2ZTc2NDRiNDNhMjVkNjQxMjg1ZjE0MTM4YjUxYTc=
data/bin/archive-ar ADDED
@@ -0,0 +1,82 @@
1
+ #!/usr/bin/env ruby
2
+ require 'archive/ar'
3
+ require 'optparse'
4
+
5
+ options = {}
6
+ OptionParser.new do |opts|
7
+ opts.banner = "Usage: archive-ar [options]"
8
+
9
+ opts.on("-t", "List the specified files in the order in which they appear in the archive, each on a
10
+ separate line. If no files are specified, all files in the archive are listed.") do |v|
11
+ options[:t] = v
12
+ end
13
+
14
+ opts.on("-x", "Extract the specified archive members into the files named by the command line argu-
15
+ ments. If no members are specified, all the members of the archive are extracted into
16
+ the current directory.
17
+
18
+ If the file does not exist, it is created; if it does exist, the owner and group will
19
+ be unchanged. The file access and modification times are the time of the extraction
20
+ (but see the -o option). The file permissions will be set to those of the file when
21
+ it was entered into the archive; this will fail if the user is not the owner of the
22
+ extracted file or the super-user.") do |v|
23
+ options[:x] = v
24
+ end
25
+
26
+ opts.on("-p", "Write the contents of the specified archive files to the standard output. If no files
27
+ are specified, the contents of all the files in the archive are written in the order
28
+ they appear in the archive.") do |v|
29
+ options[:p] = v
30
+ end
31
+
32
+ opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
33
+ options[:verbose] = v
34
+ end
35
+ end.parse!
36
+
37
+ if options[:p]
38
+ raise "illegal option combination for -p" if options[:t]
39
+ raise "illegal option combination for -p" if options[:x]
40
+
41
+ Archive::Ar.traverse(ARGV[0]) do |header, data|
42
+ if options[:verbose]
43
+ puts
44
+ puts "<#{header[:name]}>"
45
+ puts
46
+ end
47
+ puts data
48
+ end
49
+ elsif options[:t]
50
+ raise "illegal option combination for -t" if options[:x]
51
+
52
+ Archive::Ar.traverse(ARGV[0]) do |header, data|
53
+ if options[:verbose]
54
+ print header[:mode].to_s(8)
55
+ print "\t"
56
+ print header[:owner]
57
+ print "/"
58
+ print header[:group]
59
+ print "\t"
60
+ print header[:size]
61
+ print "\t"
62
+ print header[:modified]
63
+ print "\t"
64
+ print header[:name]
65
+ puts
66
+ else
67
+ puts header[:name]
68
+ end
69
+ end
70
+ elsif options[:x]
71
+ if options[:verbose]
72
+ Archive::Ar.traverse(ARGV[0]) do |header, data|
73
+ puts "x - #{header[:name]}"
74
+ Archive::Ar::Format.extract_file(Dir.pwd, header, data)
75
+ end
76
+ else
77
+ Archive::Ar.extract(ARGV[0], Dir.pwd)
78
+ end
79
+ end
80
+
81
+ #p options
82
+ #p ARGV
@@ -16,12 +16,23 @@ module Archive
16
16
  :modified => Time.at(h.shift.to_i),
17
17
  :owner => h.shift.to_i,
18
18
  :group => h.shift.to_i,
19
- :mode => h.shift,
19
+ :mode => h.shift.to_i(8),
20
20
  :start => io.tell,
21
21
  :size => h.shift.to_i,
22
22
  :magic => h.shift,
23
23
  }
24
24
  end
25
+
26
+ def extract_file(dest_dir, header, data, options = {})
27
+ file = File.join(dest_dir, header[:name])
28
+
29
+ File.open(file, "w") do |f|
30
+ f.write(data)
31
+ end
32
+
33
+ File.chmod(header[:mode], file)
34
+ #FileUtils.chown(header[:owner], header[:group], file)
35
+ end
25
36
  end
26
37
  end
27
38
  end
@@ -7,6 +7,9 @@ module Archive
7
7
  end
8
8
 
9
9
  def extract(dest_dir, options)
10
+ each do |header, data|
11
+ Archive::Ar::Format.extract_file(dest_dir, header, data, options)
12
+ end
10
13
  end
11
14
 
12
15
  def each(full = false, &block)
@@ -1,5 +1,5 @@
1
1
  module Archive
2
2
  module Ar
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -1,11 +1,11 @@
1
1
  !<arch>
2
- Gemfile 1399095295 501 20 100644 95 `
2
+ Pjjjjjj 1399095295 501 20 100755 95 `
3
3
  source 'https://rubygems.org'
4
4
 
5
5
  ( Specify your gem's dependencies in archive-ar.gemspec
6
6
  gemspec
7
7
 
8
- Semfile 1399095295 502 20 100644 95 `
8
+ Sjjjjjj 1399095295 502 20 100750 95 `
9
9
  source 'https://rubygems.org'
10
10
 
11
11
  # Specify your gem's dependencies in archive-ar.gemspec
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: archive-ar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua B. Bussdieker
@@ -55,7 +55,8 @@ dependencies:
55
55
  description:
56
56
  email:
57
57
  - jbussdieker@gmail.com
58
- executables: []
58
+ executables:
59
+ - archive-ar
59
60
  extensions: []
60
61
  extra_rdoc_files: []
61
62
  files:
@@ -66,6 +67,7 @@ files:
66
67
  - README.md
67
68
  - Rakefile
68
69
  - archive-ar.gemspec
70
+ - bin/archive-ar
69
71
  - lib/archive/ar.rb
70
72
  - lib/archive/ar/format.rb
71
73
  - lib/archive/ar/reader.rb