Class: Suvii::Extract::Targz
- Inherits:
-
Suvii::Extract
- Object
- Suvii::Extract
- Suvii::Extract::Targz
- Defined in:
- lib/suvii/extract/targz.rb
Overview
Constant Summary collapse
- CHUNK_SIZE =
65_536
- DIR_UP =
".."
- PAX_GLOBAL_HEADER =
"pax_global_header"
Constants inherited from Suvii::Extract
TARGZ_RE, UnknownFormatError, ZIP_RE
Instance Attribute Summary
Attributes inherited from Suvii::Extract
Class Method Summary collapse
-
.copy_stream(tar_io, destination) ⇒ Object
can’t use IO.copy_stream because TarReader::Entry#read has different arity when IO#read.
Instance Method Summary collapse
-
#extract_to(destination) ⇒ String
Performs archive extraction.
Methods inherited from Suvii::Extract
Constructor Details
This class inherits a constructor from Suvii::Extract
Class Method Details
.copy_stream(tar_io, destination) ⇒ Object
can’t use IO.copy_stream because TarReader::Entry#read has different arity when IO#read
13 14 15 16 17 18 19 |
# File 'lib/suvii/extract/targz.rb', line 13 def self.copy_stream(tar_io, destination) File.open(destination, "wb") do |destination_file| until tar_io.eof? destination_file.write(tar_io.read(CHUNK_SIZE)) end end end |
Instance Method Details
#extract_to(destination) ⇒ String
Performs archive extraction.
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 |
# File 'lib/suvii/extract/targz.rb', line 22 def extract_to(destination) Zlib::GzipReader.open(source) do |gz| Gem::Package::TarReader.new(gz) do |tar| tar.each do |tarfile| next if tarfile.full_name == PAX_GLOBAL_HEADER if tarfile.full_name.include?(DIR_UP) raise SecurityError, "can't write outside of destination directory, entry filename is #{tarfile.full_name.inspect}" end path = path_with_stripped_components(tarfile.full_name) destination_file = File.join(destination, path) if tarfile.directory? FileUtils.mkdir_p(destination_file) else destination_directory = File.dirname(destination_file) FileUtils.mkdir_p(destination_directory) Targz.copy_stream(tarfile, destination_file) end end end end destination end |