Created
September 4, 2012 16:24
-
-
Save mwinckler/3623058 to your computer and use it in GitHub Desktop.
Base64-encode a file's contents
This file contains hidden or 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
# Prompts for filename then base64-encodes the given file's contents and | |
# writes a new .base64 file in the same directory with the encoded contents. | |
# Handy for encoding stuff via irb. | |
require 'base64' | |
Proc.new {|filename| IO.write(filename.chomp(File.extname(filename)) + '.base64', Base64.strict_encode64(IO.binread(filename))) }.call([(print 'Filename: '), gets.rstrip][1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment