class Fastlane::Helper::FileHelper

Public Class Methods

cp_file(src, dest) click to toggle source
# File lib/fastlane/plugin/analyze_ios_ipa/helper/file_helper.rb, line 55
def self.cp_file(src, dest)
  FileUtils.cp_r(src, dest)
end
file_join(files) click to toggle source
# File lib/fastlane/plugin/analyze_ios_ipa/helper/file_helper.rb, line 7
def self.file_join(files)
  # File.join('DKNightVersion', 'Pod', 'Classes', 'UIKit') => DKNightVersion/Pod/Classes/UIKit
  File.join(files)
end
file_size(file_path, log = false) click to toggle source
# File lib/fastlane/plugin/analyze_ios_ipa/helper/file_helper.rb, line 12
def self.file_size(file_path, log = false)
  total = 0
  return 0 unless File.exist?(file_path)

  base = File.basename(file_path)
  return 0 if ['.',  '..'].include?(base)

  dir = File.dirname(file_path)
  file_path = file_join([dir, base])

  if File.directory?(file_path)
    printf("Dir: %s\n", file_path) if log
    Dir.foreach(file_path) { |file_name|
      total += file_size(file_join([file_path, file_name]), log)
    }
  else
    size = File.stat(file_path).size
    printf("File: %s - %d byte\n", file_path, size) if log
    total += size
  end

  total
end
format_size(bytes, k = 1024) click to toggle source
# File lib/fastlane/plugin/analyze_ios_ipa/helper/file_helper.rb, line 36
def self.format_size(bytes, k = 1024)
  return '0 B' unless bytes
  return '0 B' if bytes.zero?

  suffix = %w[B KB MB GB TB PB EB ZB YB]
  i = (Math.log(bytes) / Math.log(k)).floor
  base = (k ** i).to_f
  num = (bytes / base).round(2)
  "#{num} " + suffix[i]
end
glob_files(expr, dir) click to toggle source
# File lib/fastlane/plugin/analyze_ios_ipa/helper/file_helper.rb, line 47
def self.glob_files(expr, dir)
  Dir.glob(File.expand_path(expr, dir))
end
mv_file(src, dest) click to toggle source
# File lib/fastlane/plugin/analyze_ios_ipa/helper/file_helper.rb, line 51
def self.mv_file(src, dest)
  FileUtils.mv(src, dest)
end
unzip_file(src, dest) click to toggle source
# File lib/fastlane/plugin/analyze_ios_ipa/helper/file_helper.rb, line 59
def self.unzip_file(src, dest)
  FileUtils.mkdir_p(dest) unless Dir.exist?(dest)
  Zip::File.open(src) do |zip_file|
    zip_file.each do |f|
      fpath = File.join(dest, f.name)
      zip_file.extract(f, fpath) unless File.exist?(fpath)
    end
  end
end
unzip_ipa(ipa, output) click to toggle source
# File lib/fastlane/plugin/analyze_ios_ipa/helper/file_helper.rb, line 69
def self.unzip_ipa(ipa, output)
  return nil unless ipa
  return nil if ipa.empty?
  return nil unless File.exist?(ipa)

  ## create output dir if need ?
  FileUtils.rm_rf(output)
  FileUtils.mkdir_p(output)

  ## xx.ipa => xx.zip
  cp_dest = File.expand_path('app.zip', output)
  cp_file(ipa, cp_dest)

  ## xx.zip => Payload/
  unzip_file(cp_dest, output)

  File.expand_path('Payload', output)
end