Class: Omnibus::Compressor::TGZ
- Inherits:
-
Base
- Object
- Packager::Base
- Base
- Omnibus::Compressor::TGZ
- Defined in:
- lib/omnibus/compressors/tgz.rb
Constant Summary
Constants included from Util
Constants included from NullArgumentable
Instance Attribute Summary
Attributes inherited from Base
Attributes inherited from Packager::Base
DSL methods collapse
-
#compression_level(val = NULL) ⇒ Fixnum
Set or return the level of compression to use when generating the zipped tarball.
Instance Method Summary collapse
-
#gzipped_tarball ⇒ StringIO
Create the gzipped tarball.
- #package_name ⇒ Object
-
#tarball ⇒ StringIO
Create an in-memory tarball from the given packager.
-
#write_tgz ⇒ void
Write the tar.gz to disk, reading in 1024 bytes at a time to reduce memory usage.
Methods inherited from Base
Methods inherited from Packager::Base
build, #exclusions, id, #id, #initialize, #install_dir, #package_path, #resource_path, #resources_path, #run!, setup, #skip_packager, #staging_dir, #staging_dir_path
Methods included from Util
#compiler_safe_path, #copy_file, #create_directory, #create_file, #create_link, included, #path_key, #remove_directory, #remove_file, #retry_block, #shellout, #shellout!, #windows_safe_path
Methods included from Templating
included, #render_template, #render_template_content
Methods included from Sugarable
Methods included from NullArgumentable
Methods included from Logging
Methods included from Instrumentation
Methods included from Digestable
#digest, #digest_directory, included
Constructor Details
This class inherits a constructor from Omnibus::Compressor::Base
Instance Method Details
#compression_level(val = NULL) ⇒ Fixnum
Set or return the level of compression to use when generating the zipped tarball. Default: max compression.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/omnibus/compressors/tgz.rb', line 49 def compression_level(val = NULL) if null?(val) @compression_level || Zlib::BEST_COMPRESSION else unless val.is_a?(Integer) raise InvalidValue.new(:compression_level, "be an Integer") end unless val.between?(1, 9) raise InvalidValue.new(:compression_level, "be between 1-9") end @compression_level = val end end |
#gzipped_tarball ⇒ StringIO
Create the gzipped tarball. See #tarball for how the tarball is constructed. This method uses maximum gzip compression, unless the user specifies a different compression level.
130 131 132 133 134 135 136 137 138 139 |
# File 'lib/omnibus/compressors/tgz.rb', line 130 def gzipped_tarball gz = StringIO.new("") z = Zlib::GzipWriter.new(gz, compression_level) z.write(tarball.string) z.close # z was closed to write the gzip footer, so # now we need a new StringIO StringIO.new(gz.string) end |
#package_name ⇒ Object
73 74 75 |
# File 'lib/omnibus/compressors/tgz.rb', line 73 def package_name "#{packager.package_name}.tar.gz" end |
#tarball ⇒ StringIO
Create an in-memory tarball from the given packager.
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/omnibus/compressors/tgz.rb', line 105 def tarball tarfile = StringIO.new("") Gem::Package::TarWriter.new(tarfile) do |tar| path = "#{staging_dir}/#{packager.package_name}" name = packager.package_name mode = File.stat(path).mode tar.add_file(name, mode) do |tf| File.open(path, "rb") do |file| tf.write(file.read) end end end tarfile.rewind tarfile end |
#write_tgz ⇒ void
This method returns an undefined value.
Write the tar.gz to disk, reading in 1024 bytes at a time to reduce memory usage.
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/omnibus/compressors/tgz.rb', line 83 def write_tgz # Grab the contents of the gzipped tarball for reading contents = gzipped_tarball # Write the .tar.gz into the staging directory File.open("#{staging_dir}/#{package_name}", "wb") do |tgz| while chunk = contents.read(1024) tgz.write(chunk) end end # Copy the .tar.gz into the package directory FileSyncer.glob("#{staging_dir}/*.tar.gz").each do |tgz| copy_file(tgz, Config.package_dir) end end |