Module: IMW::Resources::CompressedFile
- Included in:
- Archives::Tarbz2, Archives::Targz, IMW::Resources::CompressedFiles::Bz2, IMW::Resources::CompressedFiles::Gz
- Defined in:
- lib/imw/resources/compressed_file.rb
Overview
Defines methods for decompressing a compressed file. This module isn’t used to directly extend an IMW::Resource – instead, format specific modules (e.g. - IMW::Resources::CompressedFiles::Bz2) include this module and further define the command-line flags &c. needed to make everything work.
Instance Attribute Summary collapse
-
#compression_settings ⇒ Object
Returns the value of attribute compression_settings.
Instance Method Summary collapse
-
#decompress ⇒ IMW::Resource
Decompress this file in its present directory, overwriting any existing files while keeping the original compressed file.
-
#decompress! ⇒ IMW::Resource
Decompress this file in its present directory overwriting any existing files and without saving the original compressed file.
-
#decompressed_basename ⇒ String
The basename of this resource after it is decompressed.
-
#decompressed_path ⇒ String
The path of this resource after it is decompressed.
-
#is_compressed? ⇒ true, false
Is this file compressed?.
-
#is_compressible? ⇒ true, false
Can this file be compressed?.
Instance Attribute Details
#compression_settings ⇒ Object
Returns the value of attribute compression_settings.
17 18 19 |
# File 'lib/imw/resources/compressed_file.rb', line 17 def compression_settings @compression_settings end |
Instance Method Details
#decompress ⇒ IMW::Resource
Decompress this file in its present directory, overwriting any existing files while keeping the original compressed file.
FIXME The implementation is a little stupid as the file is needlessly copied.
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/imw/resources/compressed_file.rb', line 72 def decompress should_exist!("Cannot decompress.") begin copy = cp(path + '.imw_copy') regular_file = decompress! copy.mv(path) regular_file ensure copy.mv(path) if copy && copy.exist? end end |
#decompress! ⇒ IMW::Resource
Decompress this file in its present directory overwriting any existing files and without saving the original compressed file.
58 59 60 61 62 63 |
# File 'lib/imw/resources/compressed_file.rb', line 58 def decompress! should_exist!("Cannot decompress.") program = compression_settings[:decompression_program] || compression_settings[:program] FileUtils.cd(dirname) { IMW.system(program, compression_settings[:decompress], path) } IMW.open(decompressed_path) end |
#decompressed_basename ⇒ String
The basename of this resource after it is decompressed
IMW::Resource.new('/path/to/my_file.txt.bz2').decompressed_basename
=> 'my_file.txt'
39 40 41 |
# File 'lib/imw/resources/compressed_file.rb', line 39 def decompressed_basename basename[0..-(extname.size + 1)] end |
#decompressed_path ⇒ String
The path of this resource after it is decompressed
IMW::Resource.new('/path/to/my_file.txt.bz2').decompressed_basename
=> '/path/to/my_file.txt'
49 50 51 |
# File 'lib/imw/resources/compressed_file.rb', line 49 def decompressed_path File.join(dirname, decompressed_basename) end |
#is_compressed? ⇒ true, false
Is this file compressed?
22 23 24 |
# File 'lib/imw/resources/compressed_file.rb', line 22 def is_compressed? true end |
#is_compressible? ⇒ true, false
Can this file be compressed?
29 30 31 |
# File 'lib/imw/resources/compressed_file.rb', line 29 def is_compressible? false end |