Skip to content

Instantly share code, notes, and snippets.

@takuya
Created September 9, 2016 06:53
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 takuya/ee5b10cb47768558faa5ceed107dc786 to your computer and use it in GitHub Desktop.
Save takuya/ee5b10cb47768558faa5ceed107dc786 to your computer and use it in GitHub Desktop.
#!/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