extracter 1.2.32 → 1.3.6
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 +4 -4
- data/README.md +116 -87
- data/bin/extract +2 -2
- data/doc/README.gen +117 -88
- data/extracter.gemspec +12 -32
- data/lib/extracter/base/base.rb +354 -43
- data/lib/extracter/class/extracter.rb +722 -559
- data/lib/extracter/constants/constants.rb +38 -39
- data/lib/extracter/requires/require_the_extracter_project.rb +1 -1
- data/lib/extracter/requires/require_the_toplevel_methods.rb +7 -0
- data/lib/extracter/toplevel_methods/toplevel_methods.rb +99 -0
- data/lib/extracter/version/version.rb +2 -2
- data/lib/extracter.rb +0 -0
- data/test/testing_are_we_on_windows.rb +10 -0
- data/test/testing_class_extracter.rb +3 -2
- data/test/testing_class_method_extract_what_to.rb +4 -1
- metadata +31 -35
- data/bin/extract_it +0 -13
- data/lib/extracter/class/extract_this_archive.rb +0 -289
- data/lib/extracter/extract_it/extract_it.rb +0 -241
- data/lib/extracter/toplevel_methods/is_this_a_valid_archive.rb +0 -41
- data/lib/extracter/toplevel_methods/misc.rb +0 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a95e00b9a7abf4e622cd9cde61ceec1f7d4bc5fb50df1976aa4da761ab0ca90e
|
4
|
+
data.tar.gz: 520285f7bb8b7341566ef7334f334562c5fc8628b86883726760af23b906d35e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88a1da48bfae7baae6e292fd949b00d1797567d5ab708327ebbc911aea5191945ab47d981e2e6cb43eff7518fc5baa77e63166603306137f76c04d94bacc0acc
|
7
|
+
data.tar.gz: 8b3611961a90c158d0c79e30e98da166a70e31e2c18c3983a647aa2c253de75e5f49a8988dbeed9d159c06c319aa17a31f7be102c5ba1d10de0fd1e446aeace1
|
data/README.md
CHANGED
@@ -2,168 +2,197 @@
|
|
2
2
|
[](https://www.ruby-lang.org/en/)
|
3
3
|
[](https://badge.fury.io/rb/extracter)
|
4
4
|
|
5
|
-
# Extracter
|
5
|
+
# The Extracter project
|
6
6
|
|
7
7
|
## The primary goal of the extracter gem
|
8
8
|
|
9
|
-
This gem can help the user if said user wants to
|
10
|
-
archive
|
9
|
+
This gem can help the user if said user wants to <b>extract a given
|
10
|
+
archive</b>.
|
11
11
|
|
12
|
-
|
12
|
+
Naturally this requires that ruby is installed on the target
|
13
|
+
computer.
|
13
14
|
|
14
|
-
The
|
15
|
-
|
15
|
+
The <b>extracter-gem</b> also works on Windows, since as of March 2024,
|
16
|
+
if the program <b>7z</b> (7zip) is installed. See
|
17
|
+
https://www.7-zip.org/ for binaries that will work on Windows.
|
16
18
|
|
17
|
-
|
19
|
+
## The scope of class Extracter
|
20
|
+
|
21
|
+
The scope (and goals) for <b>class Extracter</b>, which is the primary
|
22
|
+
class of the extracter-gem, are rather simple: throw any archive format
|
23
|
+
at this class, and the class will try to <b>extract</b> it. That's it.
|
24
|
+
|
25
|
+
The class can be used on the commandline as well, via
|
26
|
+
<b>bin/extracter</b>.
|
18
27
|
|
19
28
|
Note that in order to extract a given archive, some programs must
|
20
|
-
be available
|
21
|
-
|
29
|
+
be available. On Linux this typically involves programs such as
|
30
|
+
<b>tar</b>, <b>bzip2</b>, <b>xz</b> and <b>gzip</b>. On Windows
|
31
|
+
it is recommended to use <b>7-zip</b> - I found that <b>7-zip</b>
|
32
|
+
(7z) works best on Windows, much better than unzip or rar/unrar.
|
22
33
|
|
23
34
|
## How to find out whether a given file is a valid archive
|
24
35
|
|
25
|
-
You can find out whether a given input
|
26
|
-
|
36
|
+
You can find out whether a given input <b>xyz</b> is a valid archive
|
37
|
+
by making use of the following <b>toplevel-method</b>:
|
27
38
|
|
28
39
|
Extracter.is_this_a_valid_archive?(path)
|
29
40
|
|
30
|
-
This will return either true or
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
41
|
+
This will return either <b>true</b> or <b>false</b>, with
|
42
|
+
<b>false</b> being the default.
|
43
|
+
|
44
|
+
In <b>August 2022</b> the code was adapted slightly to return true
|
45
|
+
no matter if the file extension is upcased or lowercased. In other
|
46
|
+
words: a file called <b>foobar.zip</b> will work fine, as far
|
47
|
+
as this method is concerned, as will the same file but this time
|
48
|
+
called <b>foobar.ZIP</b>. I had the latter situation be an issue
|
49
|
+
when I downloaded a <b>BIOS Firmware update</b> in August 2022 -
|
50
|
+
the file had as extension <b>.ZIP</b> and Extracter did not
|
51
|
+
work as a consequence. So that was a tiny bug, or rather, an
|
52
|
+
oversight in the extracter gem - it really should work on .ZIP
|
53
|
+
files just fine as well, since these are simply .zip files,
|
54
|
+
anyway; in particular on Windows.
|
40
55
|
|
41
56
|
Keep in mind that not all archive formats have been added so far,
|
42
|
-
so this will return false even if it should instead
|
43
|
-
|
44
|
-
|
45
|
-
as time permits.
|
57
|
+
so this will return <b>false</b> even if it should instead
|
58
|
+
return true. I am willing to add support for more archive formats
|
59
|
+
in the future, as time permits.
|
46
60
|
|
47
61
|
## How to extract an archive through class Extracter, in pure ruby
|
48
62
|
|
49
|
-
You can use the following method to extract an archive
|
63
|
+
You can use the following method to <b>extract an archive</b>, in ruby,
|
50
64
|
into a specific target location on the given computer system:
|
51
65
|
|
52
|
-
Extracter.extract_what_to('foo-1.0.tar.xz', '/tmp')
|
66
|
+
Extracter.extract_what_to('foo-1.0.tar.xz', '/tmp/')
|
67
|
+
|
68
|
+
The <b>first argument</b> is the local path to an archive.
|
53
69
|
|
54
|
-
The
|
55
|
-
|
56
|
-
|
70
|
+
The second argument simply specifies the <b>target</b>, usually the
|
71
|
+
target directory, such as <b>/tmp/</b> in this case. Can't
|
72
|
+
get any simpler than that!
|
57
73
|
|
58
74
|
## Colour support
|
59
75
|
|
60
|
-
If the
|
61
|
-
support is possible for
|
76
|
+
If the <b>Colours</b> gem (<b>gem install colours</b>) is
|
77
|
+
available then <b>colour support</b> is possible for
|
78
|
+
<b>class Extracter::Extracter</b>.
|
62
79
|
|
63
|
-
For class Extracter::Extracter, whether colours are supported
|
64
|
-
determined via the method called
|
65
|
-
will be used - at the least
|
80
|
+
For class Extracter::Extracter, whether colours are supported
|
81
|
+
is determined via the method called <b>.colours?</b>. If true then
|
82
|
+
colours will be used - at the least the class will try to make
|
83
|
+
use of colours.
|
66
84
|
|
67
|
-
If you do not want to have colours, for whatever the reason or use
|
68
|
-
then you can disable this, e. g. through the method call
|
69
|
-
|
85
|
+
If you do not want to have colours, for whatever the reason or use
|
86
|
+
case, then you can disable this, e. g. through the method call
|
87
|
+
<b>.disable_colours</b> specifically, to give one example for
|
88
|
+
doing so.
|
70
89
|
|
71
90
|
## class Extracter::ExtractIt
|
72
91
|
|
73
|
-
|
74
|
-
but since as of
|
92
|
+
<b>class Extracter::ExtractIt</b> was a standalone .gem (named
|
93
|
+
<b>extract_it</b>), but since as of <b>September 2020</b> it is
|
94
|
+
now part of "<b>module Extracter</b>".
|
75
95
|
|
76
|
-
Basically this class is is a wrapper over the class Extracter, which
|
77
|
-
extract archives in general. The extraction step will go into the
|
78
|
-
working directory
|
96
|
+
Basically this class is is a wrapper over the class Extracter, which
|
97
|
+
will extract archives in general. The extraction step will go into the
|
98
|
+
current working directory, as far as class <b>ExtractIt</b> is
|
99
|
+
concerned.
|
79
100
|
|
80
101
|
## What archives and files can be extracted?
|
81
102
|
|
82
|
-
|
83
|
-
|
84
|
-
such as
|
103
|
+
<b>class Extracter</b> can extract <b>.tar.xz</b>, .tar.bz, .tar.gz, tar.Z,
|
104
|
+
<b>.zip</b> and numerous other file formats. This requires that tools
|
105
|
+
such as <b>tar</b> or <b>gzip</b> or <b>xz</b> are installed and available
|
85
106
|
on the target computer-machine, as we will simply use ruby to
|
86
107
|
shell out to these other programs. Ruby is the ultimate 'glue'
|
87
108
|
language after all.
|
88
109
|
|
89
|
-
This class can also
|
90
|
-
the multimedia_paradise project is available (
|
91
|
-
multimedia_paradise
|
110
|
+
This class can also <b>extract audio-files</b> if ffmpeg is installed and
|
111
|
+
the multimedia_paradise project is available (<b>gem install
|
112
|
+
multimedia_paradise</b>), as well as squashfs files (typically
|
92
113
|
.img files). In the latter case, such an .img file will be mounted
|
93
114
|
in the current directory. You could then simply copy the content,
|
94
115
|
to have a 'full' archive situation (mounting means read-only by
|
95
116
|
deafult in this regard, hence why the copy-operation has to be
|
96
117
|
done).
|
97
118
|
|
98
|
-
Support for extracting
|
99
|
-
added in
|
119
|
+
Support for extracting <b>.jar files</b> - used by Java - has been
|
120
|
+
added in <b>May 2020</b>.
|
100
121
|
|
101
|
-
Support for 'extracting' .pdf files has been added in
|
102
|
-
This depends on
|
122
|
+
Support for 'extracting' .pdf files has been added in <b>January 2021</b>.
|
123
|
+
This depends on <b>poppler</b>, and it is not really an extraction; we
|
103
124
|
simply convert the file to a .txt (text) file. For this functionality
|
104
|
-
the
|
125
|
+
the <b>pdf_paradise</b> project has to be available.
|
105
126
|
|
106
127
|
Support for extracting archives on windows via 7zip has been added
|
107
|
-
in
|
108
|
-
on windows; using 7zip bypassed these problems, and I
|
109
|
-
be able to extract archives on windows easily.
|
110
|
-
|
111
|
-
## Usage example:
|
112
|
-
|
113
|
-
_ = Extracter.extract_what_to('foobar-1.0.tar.bz2', '/tmp/')
|
128
|
+
in <b>August 2021</b>. This was done because I had problems with
|
129
|
+
'<b>tar</b>' on windows; using 7zip bypassed these problems, and I
|
130
|
+
needed to be able to extract archives on windows easily.
|
114
131
|
|
115
|
-
|
116
|
-
|
117
|
-
_ = Extracter.new('foo.gz', '/tmp', false) # Yes, you can extract .gz files.
|
118
|
-
_.run
|
119
|
-
|
120
|
-
The argument false means "do not yet run". You have to invoke
|
121
|
-
the .run method in that case.
|
122
|
-
|
123
|
-
The second argument to the above method is the target location,
|
124
|
-
the directory where we will extract our archive to.
|
132
|
+
## Strip components
|
125
133
|
|
126
|
-
|
134
|
+
Say that we have a path such as <b>/home/x/htop/htop-3.0.5.tar.xz</b>.
|
127
135
|
|
128
|
-
|
129
|
-
|
136
|
+
You want to extract this archive into a directory such as
|
137
|
+
<b>/tmp/</b>.
|
130
138
|
|
131
|
-
Normally this would create the following directory
|
139
|
+
Normally this would create the following directory, if everything
|
140
|
+
goes according to plan:
|
132
141
|
|
133
142
|
/tmp/htop-3.0.5/
|
134
143
|
|
135
|
-
In most cases this is what the user wants; at the least I expect
|
136
|
-
if an archive is correctly tarred up, such as a
|
144
|
+
In most cases this is what the user wants; at the least I expect
|
145
|
+
this, if an archive is correctly tarred up, such as a
|
146
|
+
<b>.tar.xz</b> file.
|
137
147
|
|
138
148
|
But there are use cases where this is not the case so. For instance,
|
139
149
|
say that you already did creat such a directory, cd-ed into it and
|
140
|
-
now just want to extract right
|
150
|
+
now just want to extract right <b>into</b> this directory. Then you
|
141
151
|
don't want to end up with:
|
142
152
|
|
143
153
|
/tmp/htop-3.0.5/htop-3.0.5/
|
144
154
|
|
145
|
-
|
146
|
-
called
|
155
|
+
<b>tar</b> allows us to avoid this, by using the commandline flag
|
156
|
+
called <b>--strip-components=1</b>.
|
147
157
|
|
148
|
-
In
|
158
|
+
In <b>October 2021</b> I needed this for the rbt-project. Since the
|
149
159
|
old class Extracter did not support it, and the code was very messy,
|
150
160
|
I ended up re-writing the project. It should now be better -
|
151
161
|
at the least cleaner than it once was. And support for the above
|
152
162
|
is possible as well now; even with a specific method call
|
153
|
-
(which is
|
163
|
+
(which is <b>.strip_components()</b>).
|
154
164
|
|
155
165
|
## Extracter.remove_archive_type
|
156
166
|
|
157
|
-
If you have a use case where you would like to remove the file
|
158
|
-
|
167
|
+
If you have a use case where you would like to remove the file suffix
|
168
|
+
from an archive, such as turning the String
|
159
169
|
"https://rubygems.org/rubygems/rubygems-3.3.14.tgz" into
|
160
|
-
"rubygems-3.3.14" exactly
|
161
|
-
|
170
|
+
the String "rubygems-3.3.14" <b>exactly</b>, then you can use
|
171
|
+
the toplevel method called
|
172
|
+
<b>Extracter.remove_archive_type()</b> for this
|
173
|
+
task.
|
162
174
|
|
163
|
-
|
175
|
+
An usage example for this follows:
|
164
176
|
|
165
177
|
Extracter.remove_archive_type(File.basename("https://rubygems.org/rubygems/rubygems-3.3.14.tgz")) # => "rubygems-3.3.14"
|
166
178
|
|
179
|
+
## Usage example of the primary API:
|
180
|
+
|
181
|
+
If you want to extract something, via ruby and Extract, use:
|
182
|
+
|
183
|
+
_ = Extracter.extract_what_to('foobar-1.0.tar.bz2', '/tmp/')
|
184
|
+
|
185
|
+
You can also use the <b>.new</b> variant, which goes like so::
|
186
|
+
|
187
|
+
_ = Extracter.new('foo.gz', '/tmp', false) # Yes, you can extract .gz files as well.
|
188
|
+
_.run
|
189
|
+
|
190
|
+
The argument false means "do not yet run". You have to invoke
|
191
|
+
the .run method in that case on your own.
|
192
|
+
|
193
|
+
The second argument to the above method is the target location,
|
194
|
+
the directory where we will extract our archive to.
|
195
|
+
|
167
196
|
|
168
197
|
## Contact information and mandatory 2FA (no longer) coming up in 2022 / 2023
|
169
198
|
|
data/bin/extract
CHANGED
@@ -2,6 +2,6 @@
|
|
2
2
|
# Encoding: UTF-8
|
3
3
|
# frozen_string_literal: true
|
4
4
|
# =========================================================================== #
|
5
|
-
require 'extracter'
|
5
|
+
require 'extracter/requires/require_the_extracter_project.rb'
|
6
6
|
|
7
|
-
Extracter.what_to(ARGV,
|
7
|
+
Extracter.what_to(ARGV, Extracter.return_pwd)
|
data/doc/README.gen
CHANGED
@@ -1,165 +1,194 @@
|
|
1
1
|
ADD_RUBY_BADGE
|
2
2
|
|
3
|
-
# Extracter
|
3
|
+
# The Extracter project
|
4
4
|
|
5
5
|
## The primary goal of the extracter gem
|
6
6
|
|
7
|
-
This gem can help the user if said user wants to
|
8
|
-
archive
|
7
|
+
This gem can help the user if said user wants to <b>extract a given
|
8
|
+
archive</b>.
|
9
9
|
|
10
|
-
|
10
|
+
Naturally this requires that ruby is installed on the target
|
11
|
+
computer.
|
11
12
|
|
12
|
-
The
|
13
|
-
|
13
|
+
The <b>extracter-gem</b> also works on Windows, since as of March 2024,
|
14
|
+
if the program <b>7z</b> (7zip) is installed. See
|
15
|
+
https://www.7-zip.org/ for binaries that will work on Windows.
|
14
16
|
|
15
|
-
|
17
|
+
## The scope of class Extracter
|
18
|
+
|
19
|
+
The scope (and goals) for <b>class Extracter</b>, which is the primary
|
20
|
+
class of the extracter-gem, are rather simple: throw any archive format
|
21
|
+
at this class, and the class will try to <b>extract</b> it. That's it.
|
22
|
+
|
23
|
+
The class can be used on the commandline as well, via
|
24
|
+
<b>bin/extracter</b>.
|
16
25
|
|
17
26
|
Note that in order to extract a given archive, some programs must
|
18
|
-
be available
|
19
|
-
|
27
|
+
be available. On Linux this typically involves programs such as
|
28
|
+
<b>tar</b>, <b>bzip2</b>, <b>xz</b> and <b>gzip</b>. On Windows
|
29
|
+
it is recommended to use <b>7-zip</b> - I found that <b>7-zip</b>
|
30
|
+
(7z) works best on Windows, much better than unzip or rar/unrar.
|
20
31
|
|
21
32
|
## How to find out whether a given file is a valid archive
|
22
33
|
|
23
|
-
You can find out whether a given input
|
24
|
-
|
34
|
+
You can find out whether a given input <b>xyz</b> is a valid archive
|
35
|
+
by making use of the following <b>toplevel-method</b>:
|
25
36
|
|
26
37
|
Extracter.is_this_a_valid_archive?(path)
|
27
38
|
|
28
|
-
This will return either true or
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
39
|
+
This will return either <b>true</b> or <b>false</b>, with
|
40
|
+
<b>false</b> being the default.
|
41
|
+
|
42
|
+
In <b>August 2022</b> the code was adapted slightly to return true
|
43
|
+
no matter if the file extension is upcased or lowercased. In other
|
44
|
+
words: a file called <b>foobar.zip</b> will work fine, as far
|
45
|
+
as this method is concerned, as will the same file but this time
|
46
|
+
called <b>foobar.ZIP</b>. I had the latter situation be an issue
|
47
|
+
when I downloaded a <b>BIOS Firmware update</b> in August 2022 -
|
48
|
+
the file had as extension <b>.ZIP</b> and Extracter did not
|
49
|
+
work as a consequence. So that was a tiny bug, or rather, an
|
50
|
+
oversight in the extracter gem - it really should work on .ZIP
|
51
|
+
files just fine as well, since these are simply .zip files,
|
52
|
+
anyway; in particular on Windows.
|
38
53
|
|
39
54
|
Keep in mind that not all archive formats have been added so far,
|
40
|
-
so this will return false even if it should instead
|
41
|
-
|
42
|
-
|
43
|
-
as time permits.
|
55
|
+
so this will return <b>false</b> even if it should instead
|
56
|
+
return true. I am willing to add support for more archive formats
|
57
|
+
in the future, as time permits.
|
44
58
|
|
45
59
|
## How to extract an archive through class Extracter, in pure ruby
|
46
60
|
|
47
|
-
You can use the following method to extract an archive
|
61
|
+
You can use the following method to <b>extract an archive</b>, in ruby,
|
48
62
|
into a specific target location on the given computer system:
|
49
63
|
|
50
|
-
Extracter.extract_what_to('foo-1.0.tar.xz', '/tmp')
|
64
|
+
Extracter.extract_what_to('foo-1.0.tar.xz', '/tmp/')
|
65
|
+
|
66
|
+
The <b>first argument</b> is the local path to an archive.
|
51
67
|
|
52
|
-
The
|
53
|
-
|
54
|
-
|
68
|
+
The second argument simply specifies the <b>target</b>, usually the
|
69
|
+
target directory, such as <b>/tmp/</b> in this case. Can't
|
70
|
+
get any simpler than that!
|
55
71
|
|
56
72
|
## Colour support
|
57
73
|
|
58
|
-
If the
|
59
|
-
support is possible for
|
74
|
+
If the <b>Colours</b> gem (<b>gem install colours</b>) is
|
75
|
+
available then <b>colour support</b> is possible for
|
76
|
+
<b>class Extracter::Extracter</b>.
|
60
77
|
|
61
|
-
For class Extracter::Extracter, whether colours are supported
|
62
|
-
determined via the method called
|
63
|
-
will be used - at the least
|
78
|
+
For class Extracter::Extracter, whether colours are supported
|
79
|
+
is determined via the method called <b>.colours?</b>. If true then
|
80
|
+
colours will be used - at the least the class will try to make
|
81
|
+
use of colours.
|
64
82
|
|
65
|
-
If you do not want to have colours, for whatever the reason or use
|
66
|
-
then you can disable this, e. g. through the method call
|
67
|
-
|
83
|
+
If you do not want to have colours, for whatever the reason or use
|
84
|
+
case, then you can disable this, e. g. through the method call
|
85
|
+
<b>.disable_colours</b> specifically, to give one example for
|
86
|
+
doing so.
|
68
87
|
|
69
88
|
## class Extracter::ExtractIt
|
70
89
|
|
71
|
-
|
72
|
-
but since as of
|
90
|
+
<b>class Extracter::ExtractIt</b> was a standalone .gem (named
|
91
|
+
<b>extract_it</b>), but since as of <b>September 2020</b> it is
|
92
|
+
now part of "<b>module Extracter</b>".
|
73
93
|
|
74
|
-
Basically this class is is a wrapper over the class Extracter, which
|
75
|
-
extract archives in general. The extraction step will go into the
|
76
|
-
working directory
|
94
|
+
Basically this class is is a wrapper over the class Extracter, which
|
95
|
+
will extract archives in general. The extraction step will go into the
|
96
|
+
current working directory, as far as class <b>ExtractIt</b> is
|
97
|
+
concerned.
|
77
98
|
|
78
99
|
## What archives and files can be extracted?
|
79
100
|
|
80
|
-
|
81
|
-
|
82
|
-
such as
|
101
|
+
<b>class Extracter</b> can extract <b>.tar.xz</b>, .tar.bz, .tar.gz, tar.Z,
|
102
|
+
<b>.zip</b> and numerous other file formats. This requires that tools
|
103
|
+
such as <b>tar</b> or <b>gzip</b> or <b>xz</b> are installed and available
|
83
104
|
on the target computer-machine, as we will simply use ruby to
|
84
105
|
shell out to these other programs. Ruby is the ultimate 'glue'
|
85
106
|
language after all.
|
86
107
|
|
87
|
-
This class can also
|
88
|
-
the multimedia_paradise project is available (
|
89
|
-
multimedia_paradise
|
108
|
+
This class can also <b>extract audio-files</b> if ffmpeg is installed and
|
109
|
+
the multimedia_paradise project is available (<b>gem install
|
110
|
+
multimedia_paradise</b>), as well as squashfs files (typically
|
90
111
|
.img files). In the latter case, such an .img file will be mounted
|
91
112
|
in the current directory. You could then simply copy the content,
|
92
113
|
to have a 'full' archive situation (mounting means read-only by
|
93
114
|
deafult in this regard, hence why the copy-operation has to be
|
94
115
|
done).
|
95
116
|
|
96
|
-
Support for extracting
|
97
|
-
added in
|
117
|
+
Support for extracting <b>.jar files</b> - used by Java - has been
|
118
|
+
added in <b>May 2020</b>.
|
98
119
|
|
99
|
-
Support for 'extracting' .pdf files has been added in
|
100
|
-
This depends on
|
120
|
+
Support for 'extracting' .pdf files has been added in <b>January 2021</b>.
|
121
|
+
This depends on <b>poppler</b>, and it is not really an extraction; we
|
101
122
|
simply convert the file to a .txt (text) file. For this functionality
|
102
|
-
the
|
123
|
+
the <b>pdf_paradise</b> project has to be available.
|
103
124
|
|
104
125
|
Support for extracting archives on windows via 7zip has been added
|
105
|
-
in
|
106
|
-
on windows; using 7zip bypassed these problems, and I
|
107
|
-
be able to extract archives on windows easily.
|
108
|
-
|
109
|
-
## Usage example:
|
110
|
-
|
111
|
-
_ = Extracter.extract_what_to('foobar-1.0.tar.bz2', '/tmp/')
|
126
|
+
in <b>August 2021</b>. This was done because I had problems with
|
127
|
+
'<b>tar</b>' on windows; using 7zip bypassed these problems, and I
|
128
|
+
needed to be able to extract archives on windows easily.
|
112
129
|
|
113
|
-
|
114
|
-
|
115
|
-
_ = Extracter.new('foo.gz', '/tmp', false) # Yes, you can extract .gz files.
|
116
|
-
_.run
|
117
|
-
|
118
|
-
The argument false means "do not yet run". You have to invoke
|
119
|
-
the .run method in that case.
|
120
|
-
|
121
|
-
The second argument to the above method is the target location,
|
122
|
-
the directory where we will extract our archive to.
|
130
|
+
## Strip components
|
123
131
|
|
124
|
-
|
132
|
+
Say that we have a path such as <b>/home/x/htop/htop-3.0.5.tar.xz</b>.
|
125
133
|
|
126
|
-
|
127
|
-
|
134
|
+
You want to extract this archive into a directory such as
|
135
|
+
<b>/tmp/</b>.
|
128
136
|
|
129
|
-
Normally this would create the following directory
|
137
|
+
Normally this would create the following directory, if everything
|
138
|
+
goes according to plan:
|
130
139
|
|
131
140
|
/tmp/htop-3.0.5/
|
132
141
|
|
133
|
-
In most cases this is what the user wants; at the least I expect
|
134
|
-
if an archive is correctly tarred up, such as a
|
142
|
+
In most cases this is what the user wants; at the least I expect
|
143
|
+
this, if an archive is correctly tarred up, such as a
|
144
|
+
<b>.tar.xz</b> file.
|
135
145
|
|
136
146
|
But there are use cases where this is not the case so. For instance,
|
137
147
|
say that you already did creat such a directory, cd-ed into it and
|
138
|
-
now just want to extract right
|
148
|
+
now just want to extract right <b>into</b> this directory. Then you
|
139
149
|
don't want to end up with:
|
140
150
|
|
141
151
|
/tmp/htop-3.0.5/htop-3.0.5/
|
142
152
|
|
143
|
-
|
144
|
-
called
|
153
|
+
<b>tar</b> allows us to avoid this, by using the commandline flag
|
154
|
+
called <b>--strip-components=1</b>.
|
145
155
|
|
146
|
-
In
|
156
|
+
In <b>October 2021</b> I needed this for the rbt-project. Since the
|
147
157
|
old class Extracter did not support it, and the code was very messy,
|
148
158
|
I ended up re-writing the project. It should now be better -
|
149
159
|
at the least cleaner than it once was. And support for the above
|
150
160
|
is possible as well now; even with a specific method call
|
151
|
-
(which is
|
161
|
+
(which is <b>.strip_components()</b>).
|
152
162
|
|
153
163
|
## Extracter.remove_archive_type
|
154
164
|
|
155
|
-
If you have a use case where you would like to remove the file
|
156
|
-
|
165
|
+
If you have a use case where you would like to remove the file suffix
|
166
|
+
from an archive, such as turning the String
|
157
167
|
"https://rubygems.org/rubygems/rubygems-3.3.14.tgz" into
|
158
|
-
"rubygems-3.3.14" exactly
|
159
|
-
|
168
|
+
the String "rubygems-3.3.14" <b>exactly</b>, then you can use
|
169
|
+
the toplevel method called
|
170
|
+
<b>Extracter.remove_archive_type()</b> for this
|
171
|
+
task.
|
160
172
|
|
161
|
-
|
173
|
+
An usage example for this follows:
|
162
174
|
|
163
175
|
Extracter.remove_archive_type(File.basename("https://rubygems.org/rubygems/rubygems-3.3.14.tgz")) # => "rubygems-3.3.14"
|
164
176
|
|
165
|
-
|
177
|
+
## Usage example of the primary API:
|
178
|
+
|
179
|
+
If you want to extract something, via ruby and Extract, use:
|
180
|
+
|
181
|
+
_ = Extracter.extract_what_to('foobar-1.0.tar.bz2', '/tmp/')
|
182
|
+
|
183
|
+
You can also use the <b>.new</b> variant, which goes like so::
|
184
|
+
|
185
|
+
_ = Extracter.new('foo.gz', '/tmp', false) # Yes, you can extract .gz files as well.
|
186
|
+
_.run
|
187
|
+
|
188
|
+
The argument false means "do not yet run". You have to invoke
|
189
|
+
the .run method in that case on your own.
|
190
|
+
|
191
|
+
The second argument to the above method is the target location,
|
192
|
+
the directory where we will extract our archive to.
|
193
|
+
|
194
|
+
ADD_CONTACT_INFORMATION
|