2014-09-15 18:34:35 +00:00
|
|
|
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]
|
2014-09-23 17:26:12 +00:00
|
|
|
system("gzip -d -c #{current_path} >#{out_path}")
|
2014-09-15 18:34:35 +00:00
|
|
|
when [66, 90]
|
2014-09-23 17:26:12 +00:00
|
|
|
system("bzip2 -d -c #{current_path} >#{out_path}")
|
2014-09-15 18:34:35 +00:00
|
|
|
else
|
|
|
|
raise "unknown compressed file format"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|