Skip to content

Instantly share code, notes, and snippets.

@slawekkolodziej
Created August 20, 2011 18:54
Show Gist options
  • Save slawekkolodziej/1159492 to your computer and use it in GitHub Desktop.
Save slawekkolodziej/1159492 to your computer and use it in GitHub Desktop.
Command line ruby script that converts binary files to html5 data uri (requires ruby 1.9)
#!/usr/bin/env ruby
require 'Base64'
require 'mime/types'
ARGV.each do |file|
puts ['File: ', file].join
puts [(MIME::Types.of file)[0], ';base64,', (Base64::encode64 (File.read file)).gsub("\n", "") ].join if FileTest::exist? file
puts "\n"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment