Skip to content

Instantly share code, notes, and snippets.

@rpetrich
Created April 21, 2013 07:44
Show Gist options
  • Save rpetrich/5428804 to your computer and use it in GitHub Desktop.
Save rpetrich/5428804 to your computer and use it in GitHub Desktop.
Convert binaries to character arrays
#!/usr/bin/env ruby
ARGV.each do |filename|
puts "// #{filename}"
myfile = File.open(filename, "r")
result = ""
myfile.each_byte { |byte| result = result + "," + byte.to_s }
myfile.close
safename = filename.gsub(".", "_").gsub("/","$").gsub("@","$")
puts "static const char #{safename}[] = { " + result[1..-1] +" };";
# puts "const size_t #{safename}_size = sizeof(#{safename});";
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment