Skip to content

Instantly share code, notes, and snippets.

@mwinckler
Created September 4, 2012 16:24
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 mwinckler/3623058 to your computer and use it in GitHub Desktop.
Save mwinckler/3623058 to your computer and use it in GitHub Desktop.
Base64-encode a file's contents
# 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