You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
asciinema.org/app/uploaders/compressed_file_uploader.rb

33 lines
598 B
Ruby

class CompressedFileUploader < BaseUploader
def decompressed_path
return unless file
cache_stored_file! unless cached?
out_path = "#{current_path}.decompressed"
unless File.exist?(out_path)
decompress(out_path)
end
out_path
end
private
def decompress(out_path)
header = File.read(current_path, 2).bytes
case header
when [31, 139]
system("gzip -d -k -c #{current_path} >#{out_path}")
when [66, 90]
system("bzip2 -d -k -c #{current_path} >#{out_path}")
else
raise "unknown compressed file format"
end
end
end