-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy patharf2
executable file
·137 lines (103 loc) · 2.95 KB
/
arf2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/env ruby
require 'epitools'
require 'slop'
__version__ = '0.1'
class Extractor
end
class Zip
end
# file or url?
# url:
# find filename/type
# * name in url?
# Whee!
# * otherwise magic!
# file:
# * determine type
#
# get extractor
# extracts streams?
# * extract it!
# otherwise
#
#
#
archive "zip", :aka=>%w[pk3 jar], :mime=>""
class Archive
def type_of_stream(start_of_archive)
MimeMagic.by_magic StringIO.new(start_of_archive)
end
end
Archive.define_types
# Two kinds of type definitions:
# declarative (define binary and commands)
# * identifies mime type
# * tries to find program to extract
# * install package if missing
# * creates destination directory
# *
# custom block (have access to the internal api and extract it with a custom algorithm)
type 'application/x-gzip' do |archive|
streamable_handle = archive.io
identify = streamable_handle.read(500)
extract_file "gunzip -c %archive > %dest"
extract_pipe "gunzip -c - > %dest"
streamable!
pipeable!
package_deps :all=>"gzip"
end
type 'application/x-compressed-tar' do
exts %w[tar.gz tgz taz]
desc "Tar archive (gzip-compressed)"
command "tar", "zxvf"
command "tar zxvf %archive %dest"
streamable!
end
type 'application/x-arj' do
exts %w(arj)
desc "ARJ archive"
package_deps :debian=>"p7zip-full"
command "7z x %archive %dest"
end
end
'application/x-arj' => [%w(arj), %w(), "ARJ archive"],
'application/x-bzip' => [%w(bz2 bz), %w(), "Bzip archive"],
'application/x-compressed-tar' => [%w(tar.gz tgz taz), %w(), "Tar archive (gzip-compressed)"],
'application/x-rar' => [%w(rar), %w(), "RAR archive"],
'application/x-rpm' => [%w(rpm), %w(), "RPM package"],
'application/x-deb' => [%w(deb), %w(), "Debian package"],
{
:zip => {
:exts => ['.zip', '.pk3', '.jar'],
:desc => "ZIP file",
:binary => "unzip",
:package => "unzip",
}
}
__DATA__
Example usage:
$ x <archive/url>
=> extract archive to <archive basename>/
$ x <archive/url> <dest>
=> extract archive to <dest>/
- if <dest> is a dir, extracts to <dest>/<archive basename>
- if <dest> isn't a dir yet, <dest> is created and the archive contents go into <dest>/
$ x l <archive/url>
=> list archive
$ x c <archive> <src> [<src>, ...]
=> create <archive> from one or more <src>
def usage
puts 'This program takes a compressed file from an url or a filename, figures out'
puts 'what type of file it is, then tries to extract it into a directory.'
puts
exts = []
for extractor in extractors:
exts.extend(extractor.exts)
puts 'Supported filetypes:\n %s' % ', '.join(exts)
puts
puts 'Usage:'
puts ' x <input file or url> [output directory]'
puts
puts 'The [output directory] is optional. By default, the current directory is used.'
puts
end