archive-tar-external 1.3.1 → 1.4.2

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.
@@ -0,0 +1,26 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIEcDCCAtigAwIBAgIBATANBgkqhkiG9w0BAQsFADA/MREwDwYDVQQDDAhkamJl
3
+ cmc5NjEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYKCZImiZPyLGQBGRYDY29t
4
+ MB4XDTE4MDMxODE1MjIwN1oXDTI4MDMxNTE1MjIwN1owPzERMA8GA1UEAwwIZGpi
5
+ ZXJnOTYxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixkARkWA2Nv
6
+ bTCCAaIwDQYJKoZIhvcNAQEBBQADggGPADCCAYoCggGBALgfaroVM6CI06cxr0/h
7
+ A+j+pc8fgpRgBVmHFaFunq28GPC3IvW7Nvc3Y8SnAW7pP1EQIbhlwRIaQzJ93/yj
8
+ u95KpkP7tA9erypnV7dpzBkzNlX14ACaFD/6pHoXoe2ltBxk3CCyyzx70mTqJpph
9
+ 75IB03ni9a8yqn8pmse+s83bFJOAqddSj009sGPcQO+QOWiNxqYv1n5EHcvj2ebO
10
+ 6hN7YTmhx7aSia4qL/quc4DlIaGMWoAhvML7u1fmo53CYxkKskfN8MOecq2vfEmL
11
+ iLu+SsVVEAufMDDFMXMJlvDsviolUSGMSNRTujkyCcJoXKYYxZSNtIiyd9etI0X3
12
+ ctu0uhrFyrMZXCedutvXNjUolD5r9KGBFSWH1R9u2I3n3SAyFF2yzv/7idQHLJJq
13
+ 74BMnx0FIq6fCpu5slAipvxZ3ZkZpEXZFr3cIBtO1gFvQWW7E/Y3ijliWJS1GQFq
14
+ 058qERadHGu1yu1dojmFRo6W2KZvY9al2yIlbkpDrD5MYQIDAQABo3cwdTAJBgNV
15
+ HRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQUFZsMapgzJimzsbaBG2Tm8j5e
16
+ AzgwHQYDVR0RBBYwFIESZGpiZXJnOTZAZ21haWwuY29tMB0GA1UdEgQWMBSBEmRq
17
+ YmVyZzk2QGdtYWlsLmNvbTANBgkqhkiG9w0BAQsFAAOCAYEAW2tnYixXQtKxgGXq
18
+ /3iSWG2bLwvxS4go3srO+aRXZHrFUMlJ5W0mCxl03aazxxKTsVVpZD8QZxvK91OQ
19
+ h9zr9JBYqCLcCVbr8SkmYCi/laxIZxsNE5YI8cC8vvlLI7AMgSfPSnn/Epq1GjGY
20
+ 6L1iRcEDtanGCIvjqlCXO9+BmsnCfEVehqZkQHeYczA03tpOWb6pon2wzvMKSsKH
21
+ ks0ApVdstSLz1kzzAqem/uHdG9FyXdbTAwH1G4ZPv69sQAFAOCgAqYmdnzedsQtE
22
+ 1LQfaQrx0twO+CZJPcRLEESjq8ScQxWRRkfuh2VeR7cEU7L7KqT10mtUwrvw7APf
23
+ DYoeCY9KyjIBjQXfbj2ke5u1hZj94Fsq9FfbEQg8ygCgwThnmkTrrKEiMSs3alYR
24
+ ORVCZpRuCPpmC8qmqxUnARDArzucjaclkxjLWvCVHeFa9UP7K3Nl9oTjJNv+7/jM
25
+ WZs4eecIcUc4tKdHxcAJ0MO/Dkqq7hGaiHpwKY76wQ1+8xAh
26
+ -----END CERTIFICATE-----
@@ -0,0 +1,134 @@
1
+ ## Description
2
+ A simple tar interface using external system calls.
3
+
4
+ ## Synopsis
5
+ ```ruby
6
+ # Assuming we have three .txt files, t1.txt, t2.txt, t3.txt ...
7
+ require 'archive/tar/external'
8
+ include Archive
9
+
10
+ t = Tar::External.new("myfile.tar")
11
+
12
+ t.create_archive("*.txt")
13
+ t.compress_archive("bzip2") # 'myfile.tar.bz2' now exists
14
+
15
+ t.uncompress_archive("bunzip2")
16
+
17
+ t.archive_name # "myfile.tar"
18
+ t.archive_info # ["t1.txt","t2.txt","t3.txt"]
19
+
20
+ t.add_to_archive("t4.txt","t5.txt")
21
+ t.expand_archive
22
+ ```
23
+
24
+ ## Constants
25
+ `VERSION`- The current version number of this library. This is a string.
26
+
27
+ ## Singleton Methods
28
+ `.new(archive_name, pattern=nil, program=nil)`
29
+
30
+ Creates an instance of an Archive::Tar::External object. The `archive_name` is
31
+ the name of the tarball. While a '.tar' extension is recommended based on
32
+ years of convention, it is not enforced.
33
+
34
+ If `pattern` is provided, then the `create_archive` method is called internally.
35
+
36
+ If `program` is provided, then the `compress_archive` method is called internally.
37
+
38
+ Note that `archive_name` name must be a string, or a `TypeError` is raised.
39
+
40
+ `.expand_archive(archive_name, file1 [, file2, ...])`
41
+
42
+ Identical to the instance method of the same name, except that you must
43
+ specify the `archive_name`, and the tar program is hard coded to `tar xf`.
44
+
45
+ `.uncompress_archive(archive_name, program='gunzip')`
46
+
47
+ Identical to the instance method of the same name, except that you must
48
+ specify the +archive_name+ as the first argument.
49
+
50
+ ## Instance Methods
51
+ ```
52
+ #add(file1 [, file2, ...])
53
+ #add_to_archive(file1 [, file2, ...])
54
+ ```
55
+
56
+ Adds a list of files to the current archive. At least one file must be
57
+ provided or an `Archive::Tar::Error` is raised.
58
+
59
+ ```
60
+ #archive_info
61
+ #info
62
+ ```
63
+
64
+ Returns an array of file names that are included within the tarball.
65
+
66
+ `#archive_name`
67
+
68
+ Returns the current archive name.
69
+
70
+ `#archive_name=`
71
+
72
+ Sets the current archive name.
73
+
74
+ ```
75
+ #compress(program="gzip")
76
+ #compress_archive(program="gzip")
77
+ ```
78
+
79
+ Compresses the tarball using the program you pass to this method. The default is "gzip".
80
+
81
+ Note that any arguments you want to be passed along with the program can simply
82
+ be included as part of the program, e.g. "gzip -f".
83
+
84
+ ```
85
+ #create(file_pattern)
86
+ #create_archive(file_pattern, options = 'cf')
87
+ ```
88
+
89
+ Creates a new tarball, including those files which match `file_pattern`
90
+ using `options`, which are set to 'cf' (create file) by default.
91
+
92
+ ```
93
+ #expand_archive(files=nil)
94
+ #extract_archive(files=nil)
95
+ ```
96
+
97
+ Expands the contents of the tarball. Note that this method does NOT delete the tarball.
98
+
99
+ If file names are provided, then only those files are extracted.
100
+
101
+ `#tar_program`
102
+
103
+ Returns the name of the tar program used. The default is "tar".
104
+
105
+ `#tar_program=(program_name)`
106
+
107
+ Sets the name of the tar program to be used.
108
+
109
+ ```
110
+ #uncompress(program="gunzip")
111
+ #uncompress_archive(program="gunzip")
112
+ ```
113
+
114
+ Uncompresses the tarball using the program you pass to this method. The default is "gunzip".
115
+
116
+ Like the `compress_archive` method, you can pass arguments along as part of the method call.
117
+
118
+ ```
119
+ #update(files)
120
+ #update_archive(files)
121
+ ```
122
+
123
+ Updates the given `files` in the archive, i.e they are added if they
124
+ are not already in the archive or have been modified.
125
+
126
+ ## Exceptions
127
+ `Archive::Tar::Error`
128
+
129
+ Raised if something goes wrong during the execution of any methods that
130
+ use the tar command internally.
131
+
132
+ `Archive::Tar::CompressError`
133
+
134
+ Raised if something goes wrong during the `compress_archive` or `uncompress_archive` methods.
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'archive/tar/external'
@@ -1,31 +1,23 @@
1
- if File::ALT_SEPARATOR
2
- if RUBY_VERSION.to_f < 1.9 && RUBY_PLATFORM !~ /java/i
3
- require 'win32/open3'
4
- else
5
- require 'open3'
6
- end
7
- else
8
- require 'open3'
9
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'open3'
10
4
 
11
5
  # The Archive module serves as a namespace only.
12
6
  module Archive
13
-
14
7
  # The Tar class serves as a toplevel class namespace only.
15
8
  class Tar
16
-
17
9
  # Raised if something goes wrong during the execution of any methods
18
10
  # which use the tar command internally.
19
11
  class Error < StandardError; end
20
12
 
21
13
  # Raised if something goes wrong during the Tar#compress_archive or
22
- # Tar#uncompress_archive methods.
14
+ # Tar#uncompress_archive methods.
23
15
  class CompressError < StandardError; end
24
16
 
25
17
  # This class encapsulates tar & zip operations.
26
18
  class Tar::External
27
19
  # The version of the archive-tar-external library.
28
- VERSION = '1.3.1'
20
+ VERSION = '1.4.2'
29
21
 
30
22
  # The name of the archive file to be used, e.g. "test.tar"
31
23
  attr_accessor :archive_name
@@ -47,18 +39,13 @@ module Archive
47
39
  # If +program+ is provided, then it compresses the archive as well by
48
40
  # calling Archive::Tar::External#compress_archive internally.
49
41
  #
50
- def initialize(archive_name, file_pattern=nil, program=nil)
42
+ def initialize(archive_name, file_pattern = nil, program = nil)
51
43
  @archive_name = archive_name.to_s
52
44
  @compressed_archive_name = nil
53
45
  @tar_program = 'tar'
54
46
 
55
- if file_pattern
56
- create_archive(file_pattern)
57
- end
58
-
59
- if program
60
- compress_archive(program)
61
- end
47
+ create_archive(file_pattern) if file_pattern
48
+ compress_archive(program) if program
62
49
  end
63
50
 
64
51
  # Assign a compressed archive name. This autogenerates the archive_name
@@ -70,32 +57,32 @@ module Archive
70
57
  # that you want to uncompress, and want to have a Tar::External object
71
58
  # around. Otherwise, use the class method Tar::External.uncompress.
72
59
  #
73
- def compressed_archive_name=(name, ext=File.extname(name))
60
+ def compressed_archive_name=(name, ext = File.extname(name))
74
61
  if ext.downcase == '.tgz'
75
- @archive_name = File.basename(name, ext.downcase) + '.tar'
62
+ @archive_name = File.basename(name, ext.downcase) << '.tar'
76
63
  else
77
64
  @archive_name = File.basename(name, ext)
78
65
  end
79
66
  @compressed_archive_name = name
80
67
  end
81
68
 
82
- # Creates the archive using +file_pattern+. Any errors that occur
83
- # here will raise a Error.
69
+ # Creates the archive using +file_pattern+ using +options+ or 'cf'
70
+ # (create file) by default.
71
+ #
72
+ # Raises an Archive::Tar::Error if a failure occurs.
84
73
  #
85
- def create_archive(file_pattern)
86
- cmd = "#{@tar_program} cf #{@archive_name} #{file_pattern}"
74
+ def create_archive(file_pattern, options = 'cf')
75
+ cmd = "#{@tar_program} #{options} #{@archive_name} #{file_pattern}"
87
76
 
88
- Open3.popen3(cmd){ |tar_in, tar_out, tar_err|
77
+ Open3.popen3(cmd) do |_tar_in, _tar_out, tar_err|
89
78
  err = tar_err.gets
90
- if err
91
- raise Error, err.chomp
92
- end
93
- }
79
+ raise Error, err.chomp if err
80
+ end
94
81
 
95
82
  self
96
83
  end
97
84
 
98
- alias :create :create_archive
85
+ alias create create_archive
99
86
 
100
87
  # Compresses the archive with +program+, or gzip if no program is
101
88
  # provided. If you want to pass arguments to +program+, merely include
@@ -103,23 +90,23 @@ module Archive
103
90
  #
104
91
  # Any errors that occur here will raise a Tar::CompressError.
105
92
  #
106
- def compress_archive(program='gzip')
93
+ def compress_archive(program = 'gzip')
107
94
  cmd = "#{program} #{@archive_name}"
108
95
 
109
- Open3.popen3(cmd){ |prog_in, prog_out, prog_err|
110
- err = prog_err.gets
96
+ Open3.popen3(cmd) do |_prog_in, _prog_out, prog_err|
97
+ err = prog_err.gets
111
98
  raise CompressError, err.chomp if err
112
99
 
113
100
  # Find the new file name with the extension. There's probably a more
114
101
  # reliable way to do this, but this should work 99% of the time.
115
102
  name = Dir["#{@archive_name}.{gz,bz2,cpio,zip}"].first
116
103
  @compressed_archive_name = name
117
- }
104
+ end
118
105
 
119
106
  self
120
107
  end
121
108
 
122
- alias :compress :compress_archive
109
+ alias compress compress_archive
123
110
 
124
111
  # Uncompresses the tarball using the program you pass to this method. The
125
112
  # default is "gunzip". Just as for +compress_archive+, you can pass
@@ -131,33 +118,31 @@ module Archive
131
118
  #
132
119
  # Any errors that occur here will raise a Tar::CompressError.
133
120
  #
134
- def uncompress_archive(program="gunzip")
135
- unless @compressed_archive_name
136
- raise CompressError, "no compressed file found"
137
- end
138
-
121
+ def uncompress_archive(program = 'gunzip')
122
+ raise CompressError, 'no compressed file found' unless @compressed_archive_name
123
+
139
124
  cmd = "#{program} #{@compressed_archive_name}"
140
125
 
141
- Open3.popen3(cmd){ |prog_in, prog_out, prog_err|
126
+ Open3.popen3(cmd) do |_prog_in, _prog_out, prog_err|
142
127
  err = prog_err.gets
143
128
  raise CompressError, err.chomp if err
144
129
  @compressed_archive_name = nil
145
- }
130
+ end
146
131
  self
147
132
  end
148
133
 
149
- alias :uncompress :uncompress_archive
134
+ alias uncompress uncompress_archive
150
135
 
151
136
  # Uncompress an existing archive, using +program+ to uncompress it.
152
137
  # The default decompression program is gunzip.
153
138
  #
154
- def self.uncompress_archive(archive, program='gunzip')
139
+ def self.uncompress_archive(archive, program = 'gunzip')
155
140
  cmd = "#{program} #{archive}"
156
141
 
157
- Open3.popen3(cmd){ |prog_in, prog_out, prog_err|
142
+ Open3.popen3(cmd) do |_prog_in, _prog_out, prog_err|
158
143
  err = prog_err.gets
159
144
  raise CompressError, err.chomp if err
160
- }
145
+ end
161
146
  end
162
147
 
163
148
  class << self
@@ -170,58 +155,54 @@ module Archive
170
155
  def archive_info
171
156
  result = []
172
157
  cmd = "#{@tar_program} tf #{@archive_name}"
173
- Open3.popen3(cmd){ |ain, aout, aerr|
158
+
159
+ Open3.popen3(cmd) do |_ain, aout, aerr|
174
160
  err = aerr.gets
175
- if err
176
- raise Error, err.chomp
177
- end
161
+ raise Error, err.chomp if err
178
162
 
179
- while output = aout.gets
163
+ while (output = aout.gets)
180
164
  result << output.chomp
181
165
  end
182
- }
166
+ end
167
+
183
168
  result
184
169
  end
185
170
 
186
- alias :info :archive_info
171
+ alias info archive_info
187
172
 
188
173
  # Adds +files+ to an already existing archive.
189
174
  #
190
175
  def add_to_archive(*files)
191
- if files.empty?
192
- raise Error, "there must be at least one file specified"
193
- end
176
+ raise Error, 'there must be at least one file specified' if files.empty?
194
177
 
195
- cmd = "#{@tar_program} rf #{@archive_name} #{files.join(" ")}"
178
+ cmd = "#{@tar_program} rf #{@archive_name} #{files.join(' ')}"
196
179
 
197
- Open3.popen3(cmd){ |ain, aout, aerr|
180
+ Open3.popen3(cmd) do |_ain, _aout, aerr|
198
181
  err = aerr.gets
199
182
  raise Error, err.chomp if err
200
- }
183
+ end
201
184
  self
202
185
  end
203
186
 
204
- alias :add :add_to_archive
187
+ alias add add_to_archive
205
188
 
206
189
  # Updates the given +files+ in the archive, i.e. they are added if they
207
190
  # are not already in the archive or have been modified.
208
191
  #
209
192
  def update_archive(*files)
210
- if files.empty?
211
- raise Error, "there must be at least one file specified"
212
- end
193
+ raise Error, 'there must be at least one file specified' if files.empty?
213
194
 
214
- cmd = "#{@tar_program} uf #{@archive_name} #{files.join(" ")}"
195
+ cmd = "#{@tar_program} uf #{@archive_name} #{files.join(' ')}"
215
196
 
216
- Open3.popen3(cmd){ |ain, aout, aerr|
197
+ Open3.popen3(cmd) do |_ain, _aout, aerr|
217
198
  err = aerr.gets
218
199
  raise Error, err.chomp if err
219
- }
200
+ end
220
201
 
221
202
  self
222
203
  end
223
204
 
224
- alias :update :update_archive
205
+ alias update update_archive
225
206
 
226
207
  # Expands the contents of the tarball. It does NOT delete the tarball.
227
208
  # If +files+ are provided, then only those files are extracted.
@@ -233,22 +214,19 @@ module Archive
233
214
  #
234
215
  def extract_archive(*files)
235
216
  cmd = "#{@tar_program} xf #{@archive_name}"
217
+ cmd = "#{cmd} #{files.join(' ')}" unless files.empty?
236
218
 
237
- unless files.empty?
238
- cmd << " " << files.join(" ")
239
- end
240
-
241
- Open3.popen3(cmd){ |ain, aout, aerr|
219
+ Open3.popen3(cmd) do |_ain, _aout, aerr|
242
220
  err = aerr.gets
243
221
  raise Error, err.chomp if err
244
- }
222
+ end
245
223
 
246
224
  self
247
225
  end
248
226
 
249
- alias :expand_archive :extract_archive
250
- alias :extract :extract_archive
251
- alias :expand :extract_archive
227
+ alias expand_archive extract_archive
228
+ alias extract extract_archive
229
+ alias expand extract_archive
252
230
 
253
231
  # A class method that behaves identically to the equivalent instance
254
232
  # method, except that you must specifiy that tarball as the first
@@ -256,15 +234,12 @@ module Archive
256
234
  #
257
235
  def self.extract_archive(archive, *files)
258
236
  cmd = "tar xf #{archive}"
237
+ cmd = "#{cmd} #{files.join(' ')}" unless files.empty?
259
238
 
260
- unless files.empty?
261
- cmd << " " << files.join(" ")
262
- end
263
-
264
- Open3.popen3(cmd){ |ain, aout, aerr|
239
+ Open3.popen3(cmd) do |_ain, _aout, aerr|
265
240
  err = aerr.gets
266
241
  raise Error, err.chomp if err
267
- }
242
+ end
268
243
 
269
244
  self
270
245
  end