dropbox_content_hasher 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.rubocop.yml +46 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +50 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/dropbox_content_hasher.gemspec +32 -0
- data/lib/dropbox_content_hasher.rb +11 -0
- data/lib/dropbox_content_hasher/calculator.rb +29 -0
- data/lib/dropbox_content_hasher/version.rb +3 -0
- metadata +103 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: dee84d920214dfdbd31289adb9f77b96cf3bd121
|
4
|
+
data.tar.gz: 9d4b9b107c4a4769e6f746ed0e8802731ebd6416
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6905d655f6c481e7610636aabde19727b60b1ae1551b288bcd2bbfc9ddb7df3d3fffffc4f71fe1064e397d17ceb03c470cbed269a25fa01404d874013fa0c0a5
|
7
|
+
data.tar.gz: d5664534e1cd16e15a64098cefa615681abeec523d653dc9ed422558a7a5267f45c5970894723b524db16698aa360149dbc2bbecb4bd08937b9c47aa4f2db951
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.3
|
3
|
+
|
4
|
+
##################### Styles ##################################
|
5
|
+
|
6
|
+
Style/Documentation:
|
7
|
+
Enabled: false
|
8
|
+
|
9
|
+
Style/SymbolArray:
|
10
|
+
Enabled: false
|
11
|
+
|
12
|
+
Style/ClassAndModuleChildren:
|
13
|
+
Exclude:
|
14
|
+
- "app/controllers/*_controller.rb"
|
15
|
+
- "app/controllers/**/*_controller.rb"
|
16
|
+
|
17
|
+
#################### Lint ##################################
|
18
|
+
|
19
|
+
Lint/AmbiguousBlockAssociation:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
##################### Metrics ##################################
|
23
|
+
|
24
|
+
Metrics/LineLength:
|
25
|
+
Max: 110
|
26
|
+
|
27
|
+
Metrics/ClassLength:
|
28
|
+
Max: 200
|
29
|
+
|
30
|
+
Metrics/ModuleLength:
|
31
|
+
Max: 200
|
32
|
+
Exclude:
|
33
|
+
- "**/*_spec.rb"
|
34
|
+
|
35
|
+
Metrics/BlockLength:
|
36
|
+
Max: 50
|
37
|
+
Exclude:
|
38
|
+
- "**/*_spec.rb"
|
39
|
+
|
40
|
+
##################### Rails ##################################
|
41
|
+
|
42
|
+
Rails:
|
43
|
+
Enabled: true
|
44
|
+
|
45
|
+
Rails/SkipsModelValidations:
|
46
|
+
Enabled: false
|
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 Igor Malinovskiy
|
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,50 @@
|
|
1
|
+
# DropboxContentHasher
|
2
|
+
|
3
|
+
[![Build Status](https://semaphoreci.com/api/v1/igormalinovskiy/dropbox_content_hasher/branches/master/shields_badge.svg)](https://semaphoreci.com/igormalinovskiy/dropbox_content_hasher)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/psyipm/dropbox_content_hasher/badges/gpa.svg)](https://codeclimate.com/github/psyipm/dropbox_content_hasher)
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/dropbox_content_hasher.svg)](https://badge.fury.io/rb/dropbox_content_hasher)
|
6
|
+
|
7
|
+
|
8
|
+
In order to allow Dropbox apps to verify uploaded contents or compare remote files to local files without downloading them, the FileMetadata object contains a hash of the file contents in the [content_hash](https://www.dropbox.com/developers/reference/content-hash) property.
|
9
|
+
|
10
|
+
This gem computes hash value of the file using dropbox algorithm.
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
gem 'dropbox_content_hasher'
|
18
|
+
```
|
19
|
+
|
20
|
+
And then execute:
|
21
|
+
|
22
|
+
$ bundle
|
23
|
+
|
24
|
+
Or install it yourself as:
|
25
|
+
|
26
|
+
$ gem install dropbox_content_hasher
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
Here is an example of running the above algorithm on [this image of the Milky Way from NASA.](https://www.dropbox.com/static/images/developers/milky-way-nasa.jpg)
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
file = Pathname.new('milky-way-nasa.jpg')
|
34
|
+
DropboxContentHasher.calculate(file)
|
35
|
+
=> "485291fa0ee50c016982abbfa943957bcd231aae0492ccbaa22c58e3997b35e0"
|
36
|
+
```
|
37
|
+
|
38
|
+
## Development
|
39
|
+
|
40
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
41
|
+
|
42
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
43
|
+
|
44
|
+
## Contributing
|
45
|
+
|
46
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/psyipm/dropbox_content_hasher.
|
47
|
+
|
48
|
+
## License
|
49
|
+
|
50
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "dropbox_content_hasher"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'dropbox_content_hasher/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'dropbox_content_hasher'
|
9
|
+
spec.version = DropboxContentHasher::VERSION
|
10
|
+
spec.authors = ['Igor Malinovskiy']
|
11
|
+
spec.email = ['psy.ipm@gmail.com']
|
12
|
+
|
13
|
+
spec.summary = 'This gem computes hash value of file'
|
14
|
+
spec.description = %q{
|
15
|
+
In order to allow Dropbox API apps to verify uploaded contents or compare remote files
|
16
|
+
to local files without downloading them, the FileMetadata object contains a hash of the
|
17
|
+
file contents in the content_hash property.
|
18
|
+
}
|
19
|
+
spec.homepage = 'https://github.com/psyipm/dropbox_content_hasher'
|
20
|
+
spec.license = 'MIT'
|
21
|
+
|
22
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
23
|
+
f.match(%r{^(test|spec|features)/})
|
24
|
+
end
|
25
|
+
spec.bindir = 'exe'
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ['lib']
|
28
|
+
|
29
|
+
spec.add_development_dependency 'bundler', '~> 1.14'
|
30
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
31
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
32
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module DropboxContentHasher
|
2
|
+
class Calculator
|
3
|
+
BLOCK_SIZE = (4 * 1024 * 1024).to_f.freeze
|
4
|
+
|
5
|
+
class FileDoesNotExist < StandardError; end
|
6
|
+
|
7
|
+
def initialize(path)
|
8
|
+
@file = Pathname.new(path)
|
9
|
+
end
|
10
|
+
|
11
|
+
def content_hash
|
12
|
+
raise FileDoesNotExist unless @file.exist?
|
13
|
+
|
14
|
+
Digest::SHA256.hexdigest(hashes.join)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def hashes
|
20
|
+
Array.new(blocks_count) do |i|
|
21
|
+
Digest::SHA256.digest(@file.binread(BLOCK_SIZE, BLOCK_SIZE * i))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def blocks_count
|
26
|
+
(@file.size / BLOCK_SIZE).ceil
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dropbox_content_hasher
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Igor Malinovskiy
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-07-01 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.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
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: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: "\n In order to allow Dropbox API apps to verify uploaded contents
|
56
|
+
or compare remote files\n to local files without downloading them, the FileMetadata
|
57
|
+
object contains a hash of the\n file contents in the content_hash property.\n
|
58
|
+
\ "
|
59
|
+
email:
|
60
|
+
- psy.ipm@gmail.com
|
61
|
+
executables: []
|
62
|
+
extensions: []
|
63
|
+
extra_rdoc_files: []
|
64
|
+
files:
|
65
|
+
- ".gitignore"
|
66
|
+
- ".rspec"
|
67
|
+
- ".rubocop.yml"
|
68
|
+
- ".travis.yml"
|
69
|
+
- Gemfile
|
70
|
+
- LICENSE.txt
|
71
|
+
- README.md
|
72
|
+
- Rakefile
|
73
|
+
- bin/console
|
74
|
+
- bin/setup
|
75
|
+
- dropbox_content_hasher.gemspec
|
76
|
+
- lib/dropbox_content_hasher.rb
|
77
|
+
- lib/dropbox_content_hasher/calculator.rb
|
78
|
+
- lib/dropbox_content_hasher/version.rb
|
79
|
+
homepage: https://github.com/psyipm/dropbox_content_hasher
|
80
|
+
licenses:
|
81
|
+
- MIT
|
82
|
+
metadata: {}
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 2.6.12
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: This gem computes hash value of file
|
103
|
+
test_files: []
|