Created
March 23, 2016 01:59
-
-
Save davispuh/9f01dbc7d38e26cc8e96 to your computer and use it in GitHub Desktop.
Show Tar archive files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/ruby | |
require 'faraday' | |
url = 'http://domain/somefile.tar' | |
conn = Faraday.new | |
header_response = conn.head(url) | |
total_size = header_response.env[:response_headers]["content-length"].to_i | |
puts "Size: #{total_size}" | |
block = 512 | |
startb = 0 | |
endb = block * 4 | |
loop do | |
break if startb > total_size | |
endb = total_size if endb > total_size | |
conn.headers = {'Range' => "bytes=#{startb}-#{endb}"} | |
response = conn.get(url) | |
data = response.body | |
0.upto(data.length / block - 1) do |i| | |
startb += block | |
file_start = startb | |
filename = data[i * block, 100].to_s | |
file_size = data[i * block + 124, 12].to_i(8) | |
startb += (file_size / block.to_f).ceil * block | |
endb = startb + block | |
puts "#{filename} : #{file_start}-#{endb} (#{file_size})" | |
if file_size.zero? and i.zero? | |
endb += block * 2 | |
elsif not file_size.zero? | |
break | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment