Module: SWFRecompress::ClassMethods
- Included in:
- SWFRecompress
- Defined in:
- lib/swf_recompress.rb
Instance Method Summary collapse
- #acquire_kzip ⇒ Object
- #command(*args) ⇒ Object
- #execute(*ramulons) ⇒ Object
- #kzip_available? ⇒ Boolean
- #kzip_md5(kzip_filename) ⇒ Object
- #recompress(filename) ⇒ Object
- #recompress_to(filename, new_filename) ⇒ Object
Instance Method Details
#acquire_kzip ⇒ Object
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/swf_recompress.rb', line 165 def acquire_kzip begin Tempfile.open('kzipmix.tar.gz', 'wb') do |f| begin download_kzipmix(f) rescue => e raise "There was an error downloading kzipmix" end extracted_kzip_filename = extract_kzipmix(f) if File.exists?(extracted_kzip_filename) extracted_kzip_md5 = kzip_md5(extracted_kzip_filename) if KZIP_MD5 == extracted_kzip_md5 FileUtils.cp(extracted_kzip_filename, LIB_KZIP) File.chmod(0755, LIB_KZIP) else raise "The MD5 of the downloaded kzip #{extracted_kzip_md5} did not match the expected MD5 #{KZIP_MD5}" end else raise "Failed to extract kzip from the downloaded kzipmix archive" end end rescue => e raise "Unable to acquire kzip utility: #{e.message}\n#{KZIP_ABOUT}#{KZIP_INSTALL_TEXT}" end end |
#command(*args) ⇒ Object
152 153 154 |
# File 'lib/swf_recompress.rb', line 152 def command(*args) args.map { |arg| '"%s"' % arg }.join(' ') end |
#execute(*ramulons) ⇒ Object
145 146 147 148 149 150 |
# File 'lib/swf_recompress.rb', line 145 def execute(*ramulons) execution = ramulons.join(' && ') results = ramulons.map { |command| `#{command} 2&> /dev/null` } puts results.join("\n") results end |
#kzip_available? ⇒ Boolean
156 157 158 |
# File 'lib/swf_recompress.rb', line 156 def kzip_available? @kzip_available ||= File.exists?(LIB_KZIP) && KZIP_MD5 == kzip_md5(LIB_KZIP) end |
#kzip_md5(kzip_filename) ⇒ Object
160 161 162 163 |
# File 'lib/swf_recompress.rb', line 160 def kzip_md5(kzip_filename) require 'digest/md5' Digest::MD5.hexdigest(File.read(kzip_filename)) end |
#recompress(filename) ⇒ Object
128 129 130 131 132 133 134 135 |
# File 'lib/swf_recompress.rb', line 128 def recompress(filename) = File.(filename) ext = File.extname() dirname = File.dirname() new_filename = File.join(dirname, '%s%s%s' % [ File.basename(, ext), '_compressed', ext ]) compressor = SWFRecompressor.new(, new_filename) compressor.recompress! end |
#recompress_to(filename, new_filename) ⇒ Object
137 138 139 140 141 142 143 |
# File 'lib/swf_recompress.rb', line 137 def recompress_to(filename, new_filename) = File.(filename) compressor = SWFRecompressor.new( File.(filename), File.(new_filename)) compressor.recompress! end |