Skip to content

Instantly share code, notes, and snippets.

@lloyd
Created August 21, 2009 23:27
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 lloyd/172504 to your computer and use it in GitHub Desktop.
Save lloyd/172504 to your computer and use it in GitHub Desktop.
#
# A simple BrowserPlus service implemented in Ruby that will calculate the
# MD5 sum of a file that a user has selected
#
# (c) Yahoo! Inc. 2008
#
class FileChecksumInstance
# args contains 'url', 'data_dir', 'temp_dir'
def initialize(args)
end
def md5(bp, args)
begin
bp.complete(Digest::MD5.hexdigest(File.open(args['file'].realpath, "rb") { |f| f.read }))
rescue Exception => err
bp_log("error", "[FileChecksum] ERROR : #{err.to_s}")
bp.error("Error", err.to_s)
end
end
end
rubyCoreletDefinition = {
'class' => "FileChecksumInstance",
'name' => "FileChecksum",
'major_version' => 1,
'minor_version' => 0,
'micro_version' => 9,
'documentation' => 'Allows client side MD5 of user selected files.',
'functions' =>
[
{
'name' => 'md5',
'documentation' => "Generate an md5 checksum of a file.",
'arguments' =>
[
{
'name' => 'file',
'type' => 'path',
'documentation' => 'The file for which to calculate a checksum.',
'required' => true
}
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment