From d50d5cfe78fbcdd66d91a5cbbc7e3c76e7282c02 Mon Sep 17 00:00:00 2001 From: yasushiito Date: Mon, 23 Jul 2012 18:42:41 +0900 Subject: [PATCH 1/1] t#29096:base64 encode tool upgrade --- script/encode64.rb | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/script/encode64.rb b/script/encode64.rb index 0519f4cd..ab171fa0 100644 --- a/script/encode64.rb +++ b/script/encode64.rb @@ -1,10 +1,33 @@ require 'base64' -d = nil -File.open(ARGV[0], 'rb') do |f| - d = f.read -end -b = Base64.encode64 d -File.open(ARGV[1], 'wb') do |f| - f.write b +def rw filename + d = nil + fn = File.basename filename, ".*" + ext = File.extname filename + ext = ext.downcase + if ext == '.png' or ext == '.gif' or ext == '.jpeg' + puts 'open '+ filename + File.open(filename, 'rb') do |f| + d = f.read + end + b = Base64.encode64(d).gsub(/\r/, '').gsub(/\n/, '') + o = File.dirname(filename)+'/' + fn + '.txt' + File.open(o, 'wb') do |f| + f.write b + end + else + puts 'skip ' + filename + end end +if File.directory?(ARGV[0]) + dr = File.expand_path(ARGV[0]) + '/*' + puts 'directory '+dr + Dir.glob dr do |filename| + if File.directory?(filename) + else + rw filename + end + end +else + rw ARGV[0] +end -- 2.11.0