Debian Codegraph @

vendor/download_lz4.rb

raw
1 #!/usr/bin/env ruby
2
3 require "pathname"
4 require "fileutils"
5 require "open-uri"
6 require "openssl"
7 require "rubygems/package"
8 require "zlib"
9
10 @debug = (ENV["DEBUG"] == "true" or ARGV.include?("--debug"))
11
12 base_dir = Pathname.new(__FILE__).expand_path.dirname.parent
13
14 lz4_version = (base_dir + "bundled_lz4_version").read.strip
15
16 lz4_base = "lz4-#{lz4_version}"
17
18 def extract_tar_gz(tar_gz_path)
19 Zlib::GzipReader.open(tar_gz_path) do |tar_io|
20 Gem::Package::TarReader.new(tar_io) do |tar|
21 tar.each do |entry|
22 p [entry.header.typeflag, entry.full_name] if @debug
23 if entry.directory?
24 FileUtils.mkdir_p(entry.full_name)
25 elsif entry.file?
26 File.open(entry.full_name, "wb") do |file|
27 file.print(entry.read)
28 end
29 end
30 end
31 end
32 end
33 end
34
35 def download(url, base)
36 ssl_verify_mode = nil
37 if /mingw/ =~ RUBY_PLATFORM
38 ssl_verify_mode = OpenSSL::SSL::VERIFY_NONE
39 end
40
41 tar = "#{base}.tar"
42 tar_gz = "#{tar}.gz"
43 URI(url).open(:ssl_verify_mode => ssl_verify_mode) do |remote_tar_gz|
44 File.open(tar_gz, "wb") do |local_tar_gz|
45 local_tar_gz.print(remote_tar_gz.read)
46 end
47 end
48 FileUtils.rm_rf(base)
49 extract_tar_gz(tar_gz)
50 FileUtils.rm_rf(tar_gz)
51 end
52
53 download("https://github.com/lz4/lz4/archive/v#{lz4_version}.tar.gz",
54 lz4_base)