ar 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.
- data/README.md +0 -0
- data/lib/ar.rb +64 -0
- metadata +47 -0
data/README.md
ADDED
File without changes
|
data/lib/ar.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
class Ar
|
2
|
+
VERSION="0.1"
|
3
|
+
|
4
|
+
ArMagic = "!<arch>\n"
|
5
|
+
ArMagicPad = "\n"
|
6
|
+
|
7
|
+
attr_reader :sourcefile, :files
|
8
|
+
|
9
|
+
def initialize(filename, options = {})
|
10
|
+
@sourcefile = filename
|
11
|
+
@files = Hash.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def load()
|
15
|
+
fp = open(@sourcefile, "r+")
|
16
|
+
magic = fp.read(ArMagic.length)
|
17
|
+
if magic != ArMagic
|
18
|
+
raise "Magic not found !"
|
19
|
+
end
|
20
|
+
|
21
|
+
begin
|
22
|
+
filename = ""
|
23
|
+
while filename != nil
|
24
|
+
filename = fp.read(16)
|
25
|
+
if filename.nil?
|
26
|
+
return
|
27
|
+
end
|
28
|
+
filename.gsub!(/\/\s+$/,"")
|
29
|
+
filename.strip!
|
30
|
+
@files[filename] = Hash.new
|
31
|
+
@files[filename]["date"] = fp.read(12).to_i
|
32
|
+
@files[filename]["uid"] = fp.read(6).to_i
|
33
|
+
@files[filename]["gid"] = fp.read(6).to_i
|
34
|
+
@files[filename]["filemode"] = fp.read(8).to_i
|
35
|
+
@files[filename]["filesize"] = fp.read(10).to_i
|
36
|
+
if @files[filename]["filesize"] != 0
|
37
|
+
fp.read(2)
|
38
|
+
@files[filename]["payload"] = fp.read(@files[filename]["filesize"])
|
39
|
+
else
|
40
|
+
@files.delete(filename)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
rescue Exception => e
|
44
|
+
puts e.message
|
45
|
+
return
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def dump(filename, path = "./")
|
50
|
+
dump_path = File.join(path, filename)
|
51
|
+
File.open(dump_path, "w+") do |f|
|
52
|
+
f.write(@files[filename]["payload"])
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def files
|
57
|
+
@files.keys
|
58
|
+
end
|
59
|
+
|
60
|
+
def get_payload(filename)
|
61
|
+
raise "File not in archive" unless self.files.include?(filename)
|
62
|
+
@files[filename]["payload"]
|
63
|
+
end
|
64
|
+
end
|
metadata
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ar
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Nicolas Szalay
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-06-24 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Pure ruby Ar
|
15
|
+
email:
|
16
|
+
- nico@rottenbytes.info
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- README.md
|
22
|
+
- lib/ar.rb
|
23
|
+
homepage: https://github.com/rottenbytes/ruby-ar
|
24
|
+
licenses: []
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ! '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
requirements: []
|
42
|
+
rubyforge_project:
|
43
|
+
rubygems_version: 1.8.25
|
44
|
+
signing_key:
|
45
|
+
specification_version: 3
|
46
|
+
summary: Ar archive manipulator
|
47
|
+
test_files: []
|