mirror of
https://gitlab.com/mbunkus/mkvtoolnix.git
synced 2025-01-07 02:34:53 +00:00
ab6455f68c
Several deprecated functions were removed: `Dir.exists?`, `File.exists?` & `FileTest.exists?`. Instead of those `FileTest.exist?` must be used (without the `s`). See the release notes for Ruby 3.2.0 as well as the issue for removing the functions: https://www.ruby-lang.org/en/news/2022/12/25/ruby-3-2-0-released/ https://bugs.ruby-lang.org/issues/17391
41 lines
903 B
Ruby
41 lines
903 B
Ruby
module Mtx::OnlineFile
|
|
@@to_unlink = []
|
|
@@mutex = Mutex.new
|
|
|
|
def self.download url, file_name = nil
|
|
@@mutex.synchronize do
|
|
FileUtils.mkdir_p "tmp"
|
|
|
|
file_name ||= url.gsub(%r{.*/}, '')
|
|
file_name = "tmp/#{file_name}"
|
|
|
|
if !FileTest.exist?(file_name)
|
|
@@to_unlink << file_name
|
|
|
|
runq "wget", url, "wget --quiet -O #{file_name} #{url}"
|
|
end
|
|
|
|
if %r{\.zip$}.match(file_name)
|
|
require "zip"
|
|
Zip::File.open(file_name, :create => false) do |zip_file|
|
|
return zip_file.entries.reject { |entry| %r{/$}.match entry.name }.first.get_input_stream.read
|
|
end
|
|
end
|
|
|
|
return IO.read(file_name)
|
|
end
|
|
end
|
|
|
|
def self.cleanup
|
|
return if c?(:KEEP_DOWNLOADED_FILES)
|
|
|
|
@@to_unlink.
|
|
select { |fn| FileTest.exist? fn }.
|
|
each { |fn| File.unlink fn }
|
|
end
|
|
end
|
|
|
|
END {
|
|
Mtx::OnlineFile.cleanup
|
|
}
|