Last active
December 10, 2015 01:58
-
-
Save pmeinhardt/4364121 to your computer and use it in GitHub Desktop.
encode files with the data-uri scheme using base64
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
#!/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