class OBF::Utils::Zipper
Public Class Methods
new(zipfile)
click to toggle source
# File lib/obf/utils.rb, line 420 def initialize(zipfile) @zipfile = zipfile end
Public Instance Methods
add(path, contents)
click to toggle source
# File lib/obf/utils.rb, line 424 def add(path, contents) @zipfile.get_output_stream(path) {|os| os.write contents } end
all_files()
click to toggle source
# File lib/obf/utils.rb, line 437 def all_files @zipfile.entries.select{|e| e.file? }.map{|e| e.to_s } end
glob(path)
click to toggle source
# File lib/obf/utils.rb, line 433 def glob(path) @zipfile.glob(path) end
read(path)
click to toggle source
# File lib/obf/utils.rb, line 428 def read(path) entry = @zipfile.glob(path).first rescue nil entry ? entry.get_input_stream.read : nil end
read_as_data(path)
click to toggle source
# File lib/obf/utils.rb, line 441 def read_as_data(path) attrs = {} raw = @zipfile.read(path) types = MIME::Types.type_for(path) attrs['content_type'] = types[0] && types[0].to_s str = "data:" + attrs['content_type'] str += ";base64," + Base64.strict_encode64(raw) attrs['data'] = str if attrs['content_type'].match(/^image/) file = Tempfile.new('file') file.binmode file.write raw file.close more_attrs = OBF::Utils.image_attrs(file.path) attrs['content_type'] ||= more_attrs['content_type'] attrs['width'] ||= more_attrs['width'] attrs['height'] ||= more_attrs['height'] end attrs end