Created
September 9, 2016 06:53
-
-
Save takuya/ee5b10cb47768558faa5ceed107dc786 to your computer and use it in GitHub Desktop.
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 'nokogiri' | |
require 'digest/md5' | |
require 'pry' | |
require 'base64' | |
def dump_attached_files( enex_path ) | |
doc = Nokogiri::Slop( open( enex_path ).read ) | |
resources = doc.search('//resource') | |
resources.each{|r| | |
ext = r.mime.text.split('/').last | |
bin = Base64.decode64(r.data.text) | |
str = Digest::MD5.hexdigest(bin) | |
open("#{str}.#{ext}",'w'){|f| | |
f.write bin | |
} | |
} | |
end | |
if __FILE__ == $0 then | |
ARGV.each{|args| | |
dump_attached_files( args ) if File.exists? args | |
} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment