Created
December 9, 2016 16:44
-
-
Save smacfarlane/81c240e5e4403159a126416e5eba180a to your computer and use it in GitHub Desktop.
Inspec Custom Matcher
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 'net/http' | |
require 'fileutils' | |
class GdalTranslate < Inspec.resource(1) | |
name 'gdal_translate' | |
def initialize(remote_file) | |
uri = URI.parse(remote_file) | |
@response = Net::HTTP.get(uri) | |
@filename = File.basename(uri.path) | |
end | |
def tiff_to_png | |
tempdir = Dir.mktmpdir | |
tempfile = File.join(tempdir, @filename) | |
File.open(tempfile, "wb") do |file| | |
file.write(@response) | |
end | |
cmd = inspec.command "gdal_translate -of PNG #{tempfile} #{tempfile}.tif" | |
result = cmd.result | |
FileUtils.remove_entry_secure(tempdir) | |
result | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment