gorge 1.0.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.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +48 -0
- data/Rakefile +23 -0
- data/gorge.gemspec +27 -0
- data/lib/gorge.rb +7 -0
- data/lib/gorge/digest/crc32.rb +47 -0
- data/lib/gorge/digest/instance.rb +24 -0
- data/lib/gorge/pathname.rb +37 -0
- data/lib/gorge/string.rb +31 -0
- data/lib/gorge/version.rb +3 -0
- metadata +113 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 571d1f13502e6d024792ccccfc30a1435853cffe
|
4
|
+
data.tar.gz: f99170a717884e083852bf6ff05d862013ca8415
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ca907bd8db031a9f3f89f2ceb1e644faaace6403694022034461ee3c9bd8c20c19d993a2e69e6e1e9f00bead1703f86144979710b590164450b5a11211329495
|
7
|
+
data.tar.gz: 321cc40244782e13794c8bc55ba3e42be4f776ea2f9867a303897fe207db676959aaf7837285f9a0e47b93d60660b91b08ddb9481e69269bc7d4ca48f626736d
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Jonathan Hefner
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# gorge
|
2
|
+
|
3
|
+
Convenient access to Ruby's Digest module via extensions to Ruby core
|
4
|
+
objects. *gorge* also provides an idiomatic `Digest::CRC32` wrapper
|
5
|
+
over the CRC32 functionality provided by Ruby's built-in Zlib module.
|
6
|
+
|
7
|
+
|
8
|
+
## API
|
9
|
+
|
10
|
+
- [Digest](http://www.rubydoc.info/gems/gorge/Digest/Instance)
|
11
|
+
- [#io](http://www.rubydoc.info/gems/gorge/Digest%2FInstance:io)
|
12
|
+
- [Digest::CRC32](http://www.rubydoc.info/gems/gorge/Digest/CRC32)
|
13
|
+
- [Pathname](http://www.rubydoc.info/gems/gorge/Pathname)
|
14
|
+
- [#file_crc32](http://www.rubydoc.info/gems/gorge/Pathname:file_crc32)
|
15
|
+
- [#file_md5](http://www.rubydoc.info/gems/gorge/Pathname:file_md5)
|
16
|
+
- [#file_sha1](http://www.rubydoc.info/gems/gorge/Pathname:file_sha1)
|
17
|
+
- [#file_sha256](http://www.rubydoc.info/gems/gorge/Pathname:file_sha256)
|
18
|
+
- [String](http://www.rubydoc.info/gems/gorge/String)
|
19
|
+
- [#crc32](http://www.rubydoc.info/gems/gorge/String:crc32)
|
20
|
+
- [#md5](http://www.rubydoc.info/gems/gorge/String:md5)
|
21
|
+
- [#sha1](http://www.rubydoc.info/gems/gorge/String:sha1)
|
22
|
+
- [#sha256](http://www.rubydoc.info/gems/gorge/String:sha256)
|
23
|
+
|
24
|
+
|
25
|
+
## Installation
|
26
|
+
|
27
|
+
Install from [Ruby Gems](https://rubygems.org/gems/gorge):
|
28
|
+
|
29
|
+
```bash
|
30
|
+
$ gem install gorge
|
31
|
+
```
|
32
|
+
|
33
|
+
Then require in your Ruby script:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
require "gorge"
|
37
|
+
```
|
38
|
+
|
39
|
+
|
40
|
+
## Contributing
|
41
|
+
|
42
|
+
Run `rake test` to run the tests. You can also run `rake irb` for an
|
43
|
+
interactive prompt that pre-loads the project code.
|
44
|
+
|
45
|
+
|
46
|
+
## License
|
47
|
+
|
48
|
+
[MIT License](https://opensource.org/licenses/MIT)
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rake/testtask"
|
3
|
+
require "yard"
|
4
|
+
|
5
|
+
|
6
|
+
YARD::Rake::YardocTask.new(:doc) do |t|
|
7
|
+
end
|
8
|
+
|
9
|
+
desc "Launch IRB with this gem pre-loaded"
|
10
|
+
task :irb do
|
11
|
+
require "gorge"
|
12
|
+
require "irb"
|
13
|
+
ARGV.clear
|
14
|
+
IRB.start
|
15
|
+
end
|
16
|
+
|
17
|
+
Rake::TestTask.new(:test) do |t|
|
18
|
+
t.libs << "test"
|
19
|
+
t.libs << "lib"
|
20
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
21
|
+
end
|
22
|
+
|
23
|
+
task :default => :test
|
data/gorge.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "gorge/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "gorge"
|
8
|
+
spec.version = Gorge::VERSION
|
9
|
+
spec.authors = ["Jonathan Hefner"]
|
10
|
+
spec.email = ["jonathan.hefner@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Convenient access to Ruby's Digest module}
|
13
|
+
spec.homepage = "https://github.com/jonathanhefner/gorge"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.15"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
26
|
+
spec.add_development_dependency "yard", "~> 0.9"
|
27
|
+
end
|
data/lib/gorge.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
class Digest::CRC32 < Digest::Class
|
2
|
+
|
3
|
+
def initialize
|
4
|
+
reset
|
5
|
+
end
|
6
|
+
|
7
|
+
# Returns the block length of the Digest.
|
8
|
+
#
|
9
|
+
# @return [Integer]
|
10
|
+
def block_length
|
11
|
+
1
|
12
|
+
end
|
13
|
+
|
14
|
+
# Returns the length in bytes of the hash value of the Digest.
|
15
|
+
#
|
16
|
+
# @return [Integer]
|
17
|
+
def digest_length
|
18
|
+
4
|
19
|
+
end
|
20
|
+
|
21
|
+
# Resets the Digest to its initial state, and returns the Digest
|
22
|
+
# modified.
|
23
|
+
#
|
24
|
+
# @return [self]
|
25
|
+
def reset
|
26
|
+
@crc32 = 0
|
27
|
+
end
|
28
|
+
|
29
|
+
# Updates the Digest using the given string, and returns the Digest
|
30
|
+
# modified.
|
31
|
+
#
|
32
|
+
# @return [self]
|
33
|
+
def update(string)
|
34
|
+
@crc32 = Zlib.crc32_combine(@crc32, Zlib.crc32(string), string.length)
|
35
|
+
self
|
36
|
+
end
|
37
|
+
|
38
|
+
alias :<< :update
|
39
|
+
|
40
|
+
# Returns the hash value of the Digest packed into a string.
|
41
|
+
#
|
42
|
+
# @return [String]
|
43
|
+
def finish
|
44
|
+
[@crc32].pack("N")
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Digest::Instance
|
2
|
+
|
3
|
+
# Updates the Digest using the entire contents of the given IO-like,
|
4
|
+
# and returns the Digest modified. Seeks to the beginning of the
|
5
|
+
# IO-like before reading, and restores its initial position after
|
6
|
+
# reading. See also +Digest::Instance#file+.
|
7
|
+
#
|
8
|
+
# @param io_like [IO, StringIO, IO-like]
|
9
|
+
# @return [self]
|
10
|
+
def io(io_like)
|
11
|
+
pos = io_like.pos # save position
|
12
|
+
io_like.seek(0)
|
13
|
+
|
14
|
+
buffer = ""
|
15
|
+
while io_like.read(16384, buffer)
|
16
|
+
self.update(buffer)
|
17
|
+
end
|
18
|
+
|
19
|
+
io_like.seek(pos) # restore position
|
20
|
+
|
21
|
+
self
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require "pathname"
|
2
|
+
|
3
|
+
class Pathname
|
4
|
+
|
5
|
+
# Returns the CRC32 checksum (in hexadecimal format) of the contents
|
6
|
+
# of the file indicated by the Pathname.
|
7
|
+
#
|
8
|
+
# @return [String]
|
9
|
+
def file_crc32
|
10
|
+
Digest::CRC32.file(self).hexdigest
|
11
|
+
end
|
12
|
+
|
13
|
+
# Returns the MD5 hash (in hexadecimal format) of the contents of the
|
14
|
+
# file indicated by the Pathname.
|
15
|
+
#
|
16
|
+
# @return [String]
|
17
|
+
def file_md5
|
18
|
+
Digest::MD5.file(self).hexdigest
|
19
|
+
end
|
20
|
+
|
21
|
+
# Returns the SHA1 hash (in hexadecimal format) of the contents of the
|
22
|
+
# file indicated by the Pathname.
|
23
|
+
#
|
24
|
+
# @return [String]
|
25
|
+
def file_sha1
|
26
|
+
Digest::SHA1.file(self).hexdigest
|
27
|
+
end
|
28
|
+
|
29
|
+
# Returns the SHA256 hash (in hexadecimal format) of the contents of
|
30
|
+
# the file indicated by the Pathname.
|
31
|
+
#
|
32
|
+
# @return [String]
|
33
|
+
def file_sha256
|
34
|
+
Digest::SHA256.file(self).hexdigest
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
data/lib/gorge/string.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
class String
|
2
|
+
|
3
|
+
# Returns the CRC32 checksum (in hexadecimal format) of the String.
|
4
|
+
#
|
5
|
+
# @return [String]
|
6
|
+
def crc32
|
7
|
+
Digest::CRC32.hexdigest(self)
|
8
|
+
end
|
9
|
+
|
10
|
+
# Returns the MD5 hash (in hexadecimal format) of the String.
|
11
|
+
#
|
12
|
+
# @return [String]
|
13
|
+
def md5
|
14
|
+
Digest::MD5.hexdigest(self)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Returns the SHA1 hash (in hexadecimal format) of the String.
|
18
|
+
#
|
19
|
+
# @return [String]
|
20
|
+
def sha1
|
21
|
+
Digest::SHA1.hexdigest(self)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Returns the SHA256 hash (in hexadecimal format) of the String.
|
25
|
+
#
|
26
|
+
# @return [String]
|
27
|
+
def sha256
|
28
|
+
Digest::SHA256.hexdigest(self)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gorge
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jonathan Hefner
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-08-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.15'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.15'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: yard
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.9'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.9'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- jonathan.hefner@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".travis.yml"
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- gorge.gemspec
|
83
|
+
- lib/gorge.rb
|
84
|
+
- lib/gorge/digest/crc32.rb
|
85
|
+
- lib/gorge/digest/instance.rb
|
86
|
+
- lib/gorge/pathname.rb
|
87
|
+
- lib/gorge/string.rb
|
88
|
+
- lib/gorge/version.rb
|
89
|
+
homepage: https://github.com/jonathanhefner/gorge
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
metadata: {}
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.4.8
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: Convenient access to Ruby's Digest module
|
113
|
+
test_files: []
|