Created
July 15, 2020 05:46
-
-
Save Kalimaha/c7744f8aa1cb96676e9f98ac951a282c to your computer and use it in GitHub Desktop.
Decompress binary content from VCR's YAML file
This file contains 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
require 'json' | |
require 'zlib' | |
require 'yaml' | |
require 'base64' | |
abort('Please proide the absolute path to VCR YAML file') if ARGV.size < 1 | |
begin | |
filepath = ARGV[0] | |
yaml = YAML.load(File.read(filepath)) | |
binary = yaml["http_interactions"].first["response"]["body"]["string"] | |
gzipped = Base64.decode64(binary) | |
reader = Zlib::GzipReader.new(StringIO.new(gzipped)) | |
uncompressed = reader.read | |
dictionary = JSON.parse(uncompressed) | |
puts | |
puts '================================================================================================================================================================' | |
puts | |
puts dictionary | |
puts | |
puts '================================================================================================================================================================' | |
puts | |
rescue => e | |
puts | |
puts 'Have you deleted "!binary " from the YAML file?' | |
puts | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment