Skip to content

Instantly share code, notes, and snippets.

@pmeinhardt
Last active December 10, 2015 01:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pmeinhardt/4364121 to your computer and use it in GitHub Desktop.
Save pmeinhardt/4364121 to your computer and use it in GitHub Desktop.
encode files with the data-uri scheme using base64
#!/usr/bin/env ruby
require 'base64'
require 'rack/mime'
if ARGV.empty?
puts "usage: #{File.basename($0)} [glob ...]"
exit 0
end
Dir[*ARGV].each do |path|
code = Base64.strict_encode64(File.read(path))
mime = Rack::Mime.mime_type(File.extname(path))
puts "#{path}: data:#{mime};base64,#{code}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment