Narnach-md5_wrapper 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +31 -0
- data/Rakefile +42 -0
- data/init.rb +1 -0
- data/lib/md5_wrapper.rb +28 -0
- data/md5_wrapper.gemspec +25 -0
- data/test/fixtures/test.txt +1 -0
- data/test/md5_wrapper_test.rb +17 -0
- metadata +64 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 Wes Oldenbeuving
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
= Md5Wrapper
|
2
|
+
|
3
|
+
Md5Wrapper wraps the command line utilities md5sum (Linux) and md5 (Mac).
|
4
|
+
Detecting which utility should be used is based on the RUBY_PLATFORM constant.
|
5
|
+
It allows obtaining the md5 hexdigest of a file and checking that a file has a specific md5 hexdigest.
|
6
|
+
It does not aim to provide all features offered by the md5(sum) utilities, but anyone who needs more features is welcome to add them.
|
7
|
+
|
8
|
+
Md5Wrapper can be used as RubyGem or as Rails plugin.
|
9
|
+
|
10
|
+
== Installation as Rails plugin
|
11
|
+
|
12
|
+
From the Rails project root, execute:
|
13
|
+
script/plugin install git://github.com/Narnach/md5_wrapper.git
|
14
|
+
|
15
|
+
== Installation as gem
|
16
|
+
|
17
|
+
Install the gem by executing:
|
18
|
+
sudo gem install Narnach-md5_wrapper --remote --source http://gems.github.com
|
19
|
+
|
20
|
+
== Example
|
21
|
+
|
22
|
+
Get the md5 hexdigest for a file.
|
23
|
+
Md5Wrapper.get_md5sum('foo.txt') #=> 'abcdabcdabcdabcdabcdabcdabcdabcd'
|
24
|
+
|
25
|
+
Check the correct md5 hexdigest against a file.
|
26
|
+
Md5Wrapper.check_md5sum('foo.txt', 'abcdabcdabcdabcdabcdabcdabcdabcd') #=> true
|
27
|
+
|
28
|
+
Check an incorrect md5 hexdigest against a file.
|
29
|
+
Md5Wrapper.check_md5sum('foo.txt', 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa') #=> false
|
30
|
+
|
31
|
+
Copyright (c) 2008 Wes Oldenbeuving, released under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
require "rake/gempackagetask"
|
5
|
+
|
6
|
+
desc 'Default: run unit tests.'
|
7
|
+
task :default => :test
|
8
|
+
|
9
|
+
desc 'Test the md5_wrapper plugin.'
|
10
|
+
Rake::TestTask.new(:test) do |t|
|
11
|
+
t.libs << 'lib'
|
12
|
+
t.pattern = 'test/**/*_test.rb'
|
13
|
+
t.verbose = true
|
14
|
+
end
|
15
|
+
|
16
|
+
desc 'Generate documentation for the md5_wrapper plugin.'
|
17
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
18
|
+
rdoc.rdoc_dir = 'rdoc'
|
19
|
+
rdoc.title = 'Md5Wrapper'
|
20
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
21
|
+
rdoc.rdoc_files.include('README')
|
22
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
23
|
+
end
|
24
|
+
|
25
|
+
begin
|
26
|
+
# Parse gemspec using the github safety level.
|
27
|
+
data = File.read('md5_wrapper.gemspec')
|
28
|
+
spec = nil
|
29
|
+
Thread.new { spec = eval("$SAFE = 3\n%s" % data)}.join
|
30
|
+
|
31
|
+
# Create the gem tasks
|
32
|
+
Rake::GemPackageTask.new(spec) do |package|
|
33
|
+
package.gem_spec = spec
|
34
|
+
end
|
35
|
+
rescue Exception => e
|
36
|
+
printf "WARNING: Error caught (%s): %s\n", e.class.name, e.message
|
37
|
+
end
|
38
|
+
|
39
|
+
desc 'Package and install the gem for the current version'
|
40
|
+
task :install => :gem do
|
41
|
+
system "sudo gem install -l pkg/md5_wrapper-%s.gem" % spec.version
|
42
|
+
end
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'md5_wrapper'
|
data/lib/md5_wrapper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Wraps the command line utilities md5sum (Linux) and md5 (Mac).
|
2
|
+
class Md5Wrapper
|
3
|
+
class << self
|
4
|
+
# Validate that the file has this md5 hexdigest.
|
5
|
+
def check_md5sum(filename, md5sum)
|
6
|
+
raise ArgumentError, "Invalid md5sum" unless md5sum.size == 32
|
7
|
+
raise ArgumentError, "Invalid file" unless File.exist? filename and File.file? filename and File.readable? filename
|
8
|
+
|
9
|
+
if RUBY_PLATFORM =~ /darwin/
|
10
|
+
md5 = `md5 #{filename} 2>&1`.strip[-32,32]
|
11
|
+
return md5 == md5sum
|
12
|
+
else # linux
|
13
|
+
cmd = "echo \"#{md5sum} *#{filename}\" | md5sum -c --status 2>&1"
|
14
|
+
return system(cmd)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# Extract the md5 hexdigest from a file.
|
19
|
+
def get_md5sum(filename)
|
20
|
+
raise ArgumentError, "Invalid file" unless File.exist? filename and File.file? filename and File.readable? filename
|
21
|
+
if RUBY_PLATFORM =~ /darwin/
|
22
|
+
return `md5 #{filename} 2>&1`.strip[-32,32]
|
23
|
+
else # linux
|
24
|
+
return `md5sum -b #{filename} 2>&1`[0,32]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/md5_wrapper.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
# Project
|
3
|
+
s.name = 'md5_wrapper'
|
4
|
+
s.summary = "Md5Wrapper wraps the command line utilities md5sum (Linux) and md5 (Mac)."
|
5
|
+
s.description = "It allows obtaining the md5 hexdigest of a file and checking that a file has a specific md5 hexdigest."
|
6
|
+
s.version = '0.3.0'
|
7
|
+
s.date = '2008-08-05'
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Wes Oldenbeuving"]
|
10
|
+
s.email = "narnach@gmail.com"
|
11
|
+
s.homepage = "http://www.github.com/Narnach/md5_wrapper"
|
12
|
+
|
13
|
+
# Files
|
14
|
+
s.require_path = "lib"
|
15
|
+
s.files = ['md5_wrapper.gemspec', 'MIT-LICENSE', 'README.rdoc', 'Rakefile', 'init.rb', 'lib/md5_wrapper.rb', 'test/md5_wrapper_test.rb', 'test/fixtures/test.txt']
|
16
|
+
s.test_files = ['test/md5_wrapper_test.rb']
|
17
|
+
|
18
|
+
# rdoc
|
19
|
+
s.has_rdoc = true
|
20
|
+
s.extra_rdoc_files = %w[ README.rdoc MIT-LICENSE]
|
21
|
+
s.rdoc_options << '--inline-source' << '--line-numbers' << '--main' << 'README.rdoc'
|
22
|
+
|
23
|
+
# Requirements
|
24
|
+
s.required_ruby_version = ">= 1.8.0"
|
25
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
test
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'md5_wrapper'
|
3
|
+
|
4
|
+
class Md5WrapperTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
@fixture = File.expand_path(File.join(File.dirname(__FILE__),'fixtures','test.txt'))
|
7
|
+
@md5sum = 'd8e8fca2dc0f896fd7cb4cb0031ba249'
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_get_md5sum
|
11
|
+
assert_equal @md5sum, Md5Wrapper.get_md5sum(@fixture)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_check_md5sum
|
15
|
+
assert Md5Wrapper.check_md5sum(@fixture, @md5sum)
|
16
|
+
end
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: Narnach-md5_wrapper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Wes Oldenbeuving
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-08-05 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: It allows obtaining the md5 hexdigest of a file and checking that a file has a specific md5 hexdigest.
|
17
|
+
email: narnach@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.rdoc
|
24
|
+
- MIT-LICENSE
|
25
|
+
files:
|
26
|
+
- md5_wrapper.gemspec
|
27
|
+
- MIT-LICENSE
|
28
|
+
- README.rdoc
|
29
|
+
- Rakefile
|
30
|
+
- init.rb
|
31
|
+
- lib/md5_wrapper.rb
|
32
|
+
- test/md5_wrapper_test.rb
|
33
|
+
- test/fixtures/test.txt
|
34
|
+
has_rdoc: true
|
35
|
+
homepage: http://www.github.com/Narnach/md5_wrapper
|
36
|
+
post_install_message:
|
37
|
+
rdoc_options:
|
38
|
+
- --inline-source
|
39
|
+
- --line-numbers
|
40
|
+
- --main
|
41
|
+
- README.rdoc
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 1.8.0
|
49
|
+
version:
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: "0"
|
55
|
+
version:
|
56
|
+
requirements: []
|
57
|
+
|
58
|
+
rubyforge_project:
|
59
|
+
rubygems_version: 1.2.0
|
60
|
+
signing_key:
|
61
|
+
specification_version: 2
|
62
|
+
summary: Md5Wrapper wraps the command line utilities md5sum (Linux) and md5 (Mac).
|
63
|
+
test_files:
|
64
|
+
- test/md5_wrapper_test.rb
|