shrine-content_addressable 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +11 -11
- data/.travis.yml +20 -20
- data/CHANGELOG.md +5 -1
- data/CODE_OF_CONDUCT.md +74 -74
- data/Gemfile +6 -6
- data/LICENSE.txt +21 -21
- data/README.md +3 -2
- data/Rakefile +12 -12
- data/bin/console +14 -14
- data/bin/setup +8 -8
- data/lib/content_addressable_file.rb +1 -1
- data/lib/shrine/plugins/content_addressable.rb +85 -85
- data/shrine-content_addressable.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f20e5a9c6b4b2a0414709d361b48b4720595775
|
4
|
+
data.tar.gz: 88466ca818aea8fd7bab8e8bfcc39702333711ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae88579392a93003c7e9c547bbe54cc7109e8441d1d17aa8632bd7911ee7cca04739f1358d9c4ebec994b2f98af0b75292dc65746cd031adeb50b0058577b718
|
7
|
+
data.tar.gz: c3be4fd82bd522cea507600680c0e35ec085af7a3ace7b72691a3947f64442340ed4025f7afbd727717ba8a36c1464a4453365cb3a45e56b74088be093d70c0c
|
data/.gitignore
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
/.bundle/
|
2
|
-
/.yardoc
|
3
|
-
/_yardoc/
|
4
|
-
/coverage/
|
5
|
-
/doc/
|
6
|
-
/pkg/
|
7
|
-
/spec/reports/
|
8
|
-
/tmp/
|
9
|
-
|
10
|
-
.idea/
|
11
|
-
Gemfile.lock
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/_yardoc/
|
4
|
+
/coverage/
|
5
|
+
/doc/
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/tmp/
|
9
|
+
|
10
|
+
.idea/
|
11
|
+
Gemfile.lock
|
data/.travis.yml
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
sudo: false
|
2
|
-
language: ruby
|
3
|
-
cache: bundler
|
4
|
-
rvm:
|
5
|
-
- 2.3.0
|
6
|
-
- 2.4
|
7
|
-
- 2.5
|
8
|
-
- 2.6
|
9
|
-
- rbx-3
|
10
|
-
- ruby-head
|
11
|
-
matrix:
|
12
|
-
allow_failures:
|
13
|
-
- rvm: ruby-head
|
14
|
-
- rvm: rbx-3
|
15
|
-
- rvm: 2.6
|
16
|
-
before_install:
|
17
|
-
- gem update --system
|
18
|
-
- gem --version
|
19
|
-
install:
|
20
|
-
- bundle install --with development --jobs=3 --retry=3 --path=${BUNDLE_PATH:-vendor/bundle}
|
1
|
+
sudo: false
|
2
|
+
language: ruby
|
3
|
+
cache: bundler
|
4
|
+
rvm:
|
5
|
+
- 2.3.0
|
6
|
+
- 2.4
|
7
|
+
- 2.5
|
8
|
+
- 2.6
|
9
|
+
- rbx-3
|
10
|
+
- ruby-head
|
11
|
+
matrix:
|
12
|
+
allow_failures:
|
13
|
+
- rvm: ruby-head
|
14
|
+
- rvm: rbx-3
|
15
|
+
- rvm: 2.6
|
16
|
+
before_install:
|
17
|
+
- gem update --system
|
18
|
+
- gem --version
|
19
|
+
install:
|
20
|
+
- bundle install --with development --jobs=3 --retry=3 --path=${BUNDLE_PATH:-vendor/bundle}
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,12 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 0.3.1
|
4
|
+
|
5
|
+
- Fix `ContentAddressableFile#open` without a block
|
6
|
+
|
3
7
|
## 0.3.0
|
4
8
|
|
5
|
-
- Add read only (no mass deletion) for `ContentAddressableFile
|
9
|
+
- Add read only (no mass deletion) for `ContentAddressableFile`
|
6
10
|
- Add `#digest` and related functionality
|
7
11
|
|
8
12
|
## 0.2.0
|
data/CODE_OF_CONDUCT.md
CHANGED
@@ -1,74 +1,74 @@
|
|
1
|
-
# Contributor Covenant Code of Conduct
|
2
|
-
|
3
|
-
## Our Pledge
|
4
|
-
|
5
|
-
In the interest of fostering an open and welcoming environment, we as
|
6
|
-
contributors and maintainers pledge to making participation in our project and
|
7
|
-
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
-
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
-
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
-
orientation.
|
11
|
-
|
12
|
-
## Our Standards
|
13
|
-
|
14
|
-
Examples of behavior that contributes to creating a positive environment
|
15
|
-
include:
|
16
|
-
|
17
|
-
* Using welcoming and inclusive language
|
18
|
-
* Being respectful of differing viewpoints and experiences
|
19
|
-
* Gracefully accepting constructive criticism
|
20
|
-
* Focusing on what is best for the community
|
21
|
-
* Showing empathy towards other community members
|
22
|
-
|
23
|
-
Examples of unacceptable behavior by participants include:
|
24
|
-
|
25
|
-
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
-
advances
|
27
|
-
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
-
* Public or private harassment
|
29
|
-
* Publishing others' private information, such as a physical or electronic
|
30
|
-
address, without explicit permission
|
31
|
-
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
-
professional setting
|
33
|
-
|
34
|
-
## Our Responsibilities
|
35
|
-
|
36
|
-
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
-
behavior and are expected to take appropriate and fair corrective action in
|
38
|
-
response to any instances of unacceptable behavior.
|
39
|
-
|
40
|
-
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
-
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
-
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
-
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
-
threatening, offensive, or harmful.
|
45
|
-
|
46
|
-
## Scope
|
47
|
-
|
48
|
-
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
-
when an individual is representing the project or its community. Examples of
|
50
|
-
representing a project or community include using an official project e-mail
|
51
|
-
address, posting via an official social media account, or acting as an appointed
|
52
|
-
representative at an online or offline event. Representation of a project may be
|
53
|
-
further defined and clarified by project maintainers.
|
54
|
-
|
55
|
-
## Enforcement
|
56
|
-
|
57
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
-
reported by contacting the project team at derk-jan+github@karrenbeld.info. All
|
59
|
-
complaints will be reviewed and investigated and will result in a response that
|
60
|
-
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
-
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
-
Further details of specific enforcement policies may be posted separately.
|
63
|
-
|
64
|
-
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
-
faith may face temporary or permanent repercussions as determined by other
|
66
|
-
members of the project's leadership.
|
67
|
-
|
68
|
-
## Attribution
|
69
|
-
|
70
|
-
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
-
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
-
|
73
|
-
[homepage]: http://contributor-covenant.org
|
74
|
-
[version]: http://contributor-covenant.org/version/1/4/
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at derk-jan+github@karrenbeld.info. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
3
|
-
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
4
|
-
|
5
|
-
# Specify your gem's dependencies in shrine-content_addressable.gemspec
|
6
|
-
gemspec
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in shrine-content_addressable.gemspec
|
6
|
+
gemspec
|
data/LICENSE.txt
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2018 Derk-Jan Karrenbeld
|
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.
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Derk-Jan Karrenbeld
|
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
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
-
#
|
1
|
+
# Shrine::Plugins::ContentAddressable
|
2
2
|
[![Build Status](https://travis-ci.com/SleeplessByte/shrine-content_addressable.svg?branch=master)](https://travis-ci.com/SleeplessByte/content_addressable)
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/shrine-content_addressable.svg)](https://badge.fury.io/rb/shrine-content_addressable)
|
4
|
-
[![MIT license](http://img.shields.io/badge/license-MIT-brightgreen.svg)](http://opensource.org/licenses/MIT)
|
4
|
+
[![MIT license](http://img.shields.io/badge/license-MIT-brightgreen.svg)](http://opensource.org/licenses/MIT)
|
5
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/b85f82e8889ad5546f82/maintainability)](https://codeclimate.com/github/SleeplessByte/resumable_job/maintainability)
|
5
6
|
|
6
7
|
Generate content addressable locations for shrine uploads.
|
7
8
|
|
data/Rakefile
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'bundler/gem_tasks'
|
4
|
-
require 'rake/testtask'
|
5
|
-
|
6
|
-
Rake::TestTask.new(:test) do |t|
|
7
|
-
t.libs << 'test'
|
8
|
-
t.libs << 'lib'
|
9
|
-
t.test_files = FileList['test/**/*_test.rb']
|
10
|
-
end
|
11
|
-
|
12
|
-
task default: :test
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rake/testtask'
|
5
|
+
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
7
|
+
t.libs << 'test'
|
8
|
+
t.libs << 'lib'
|
9
|
+
t.test_files = FileList['test/**/*_test.rb']
|
10
|
+
end
|
11
|
+
|
12
|
+
task default: :test
|
data/bin/console
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'bundler/setup'
|
4
|
-
require 'shrine/plugins/content_addressable'
|
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__)
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'shrine/plugins/content_addressable'
|
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
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
#!/usr/bin/env bash
|
2
|
-
set -euo pipefail
|
3
|
-
IFS=$'\n\t'
|
4
|
-
set -vx
|
5
|
-
|
6
|
-
bundle install
|
7
|
-
|
8
|
-
# Do any other automated setup that you need to do here
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
set -euo pipefail
|
3
|
+
IFS=$'\n\t'
|
4
|
+
set -vx
|
5
|
+
|
6
|
+
bundle install
|
7
|
+
|
8
|
+
# Do any other automated setup that you need to do here
|
@@ -240,7 +240,7 @@ class ContentAddressableFile
|
|
240
240
|
# Returns an opened IO object for the uploaded file by calling `#open`
|
241
241
|
# on the storage.
|
242
242
|
def io
|
243
|
-
@io ||=
|
243
|
+
@io ||= pin_storage(:open, id)
|
244
244
|
end
|
245
245
|
|
246
246
|
# rubocop:disable Style/RescueModifier
|
@@ -1,85 +1,85 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'shrine'
|
4
|
-
require 'shrine/plugins/signature'
|
5
|
-
|
6
|
-
require 'multihashes'
|
7
|
-
require 'digest'
|
8
|
-
|
9
|
-
class Shrine
|
10
|
-
module Plugins
|
11
|
-
##
|
12
|
-
# plugin :signature
|
13
|
-
# plugin :content_addressable
|
14
|
-
#
|
15
|
-
# This plugin uses the {Signature} plugin to turn the content into a content
|
16
|
-
# addressable, which simply means the digest of the content is now
|
17
|
-
# the location, and location the file by digest becomes possible.
|
18
|
-
#
|
19
|
-
# The results are wrapped in a multihash, so you may change your hashing
|
20
|
-
# method in production, whilst not losing access to the old hashes. This
|
21
|
-
# works by adding metadata to the hash of what function was used.
|
22
|
-
# https://github.com/multiformats/multihash
|
23
|
-
#
|
24
|
-
# @example Setup the plugin using sha256
|
25
|
-
#
|
26
|
-
# plugin :content_addressable, hash: :sha256
|
27
|
-
# # /1220142711d38ca7a33c5218416f8ffcc64648ca4616a625b5e0a0ab3da1911d5d7a
|
28
|
-
#
|
29
|
-
# @example You can also prefix the final location, for example to make the
|
30
|
-
# location ready for IPFS
|
31
|
-
# https://ipfs.io/
|
32
|
-
#
|
33
|
-
# plugin :content_addressable, hash: :sha256, prefix: 'ipfs'
|
34
|
-
# # /ipfs/1220142711d38ca7a33c5218416f8ffcc64648ca4616a625b5e0a0ab3da1911d5d7a
|
35
|
-
#
|
36
|
-
# @example Reading out the hash data
|
37
|
-
#
|
38
|
-
# location = '/ipfs/1220142711d38ca7a33c5218416f8ffcc64648ca4616a625b5e0a0ab3da1911d5d7a'
|
39
|
-
# hash = location.rpartition('/').last
|
40
|
-
# out = Multihashes.decode [hash].pack('H*')
|
41
|
-
# # => {:code=>18, :hash_function=>"sha2-256", :length=>32, :digest=>"\x14'\x11\xD3\x8C\xA7\xA3<R\x18Ao\x8F\xFC\xC6FH\xCAF\x16\xA6%\xB5\xE0\xA0\xAB=\xA1\x 91\x1D]z"}
|
42
|
-
#
|
43
|
-
module ContentAddressable
|
44
|
-
|
45
|
-
MULTIHASH_LOOKUP = {
|
46
|
-
md5: 'md5',
|
47
|
-
sha1: 'sha1',
|
48
|
-
sha256: 'sha2-256',
|
49
|
-
sha512: 'sha2-512'
|
50
|
-
}.freeze
|
51
|
-
|
52
|
-
def self.configure(uploader, opts = {})
|
53
|
-
uploader.opts[:content_addressable_hash] = opts.fetch(:hash, uploader.opts[:content_addressable_hash])
|
54
|
-
uploader.opts[:content_addressable_multihash] = opts.fetch(:multihash, uploader.opts[:content_addressable_multihash])
|
55
|
-
uploader.opts[:content_addressable_prefix] = opts.fetch(:prefix, uploader.opts[:content_addressable_prefix])
|
56
|
-
end
|
57
|
-
|
58
|
-
module InstanceMethods
|
59
|
-
def content_addressable_hash
|
60
|
-
(opts[:content_addressable_hash] || 'sha256').to_sym
|
61
|
-
end
|
62
|
-
|
63
|
-
def content_addressable_multihash
|
64
|
-
String(
|
65
|
-
opts[:content_addressable_multihash] ||
|
66
|
-
MULTIHASH_LOOKUP.fetch(content_addressable_hash)
|
67
|
-
)
|
68
|
-
end
|
69
|
-
|
70
|
-
def content_addressable_hex(io)
|
71
|
-
digest = calculate_signature(io, content_addressable_hash, format: :none)
|
72
|
-
Multihashes.encode(digest, content_addressable_multihash)
|
73
|
-
.unpack('H*')
|
74
|
-
.first
|
75
|
-
end
|
76
|
-
|
77
|
-
def generate_location(io, _)
|
78
|
-
[opts[:content_addressable_prefix], content_addressable_hex(io)].compact.join('/')
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
register_plugin(:content_addressable, ContentAddressable)
|
84
|
-
end
|
85
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'shrine'
|
4
|
+
require 'shrine/plugins/signature'
|
5
|
+
|
6
|
+
require 'multihashes'
|
7
|
+
require 'digest'
|
8
|
+
|
9
|
+
class Shrine
|
10
|
+
module Plugins
|
11
|
+
##
|
12
|
+
# plugin :signature
|
13
|
+
# plugin :content_addressable
|
14
|
+
#
|
15
|
+
# This plugin uses the {Signature} plugin to turn the content into a content
|
16
|
+
# addressable, which simply means the digest of the content is now
|
17
|
+
# the location, and location the file by digest becomes possible.
|
18
|
+
#
|
19
|
+
# The results are wrapped in a multihash, so you may change your hashing
|
20
|
+
# method in production, whilst not losing access to the old hashes. This
|
21
|
+
# works by adding metadata to the hash of what function was used.
|
22
|
+
# https://github.com/multiformats/multihash
|
23
|
+
#
|
24
|
+
# @example Setup the plugin using sha256
|
25
|
+
#
|
26
|
+
# plugin :content_addressable, hash: :sha256
|
27
|
+
# # /1220142711d38ca7a33c5218416f8ffcc64648ca4616a625b5e0a0ab3da1911d5d7a
|
28
|
+
#
|
29
|
+
# @example You can also prefix the final location, for example to make the
|
30
|
+
# location ready for IPFS
|
31
|
+
# https://ipfs.io/
|
32
|
+
#
|
33
|
+
# plugin :content_addressable, hash: :sha256, prefix: 'ipfs'
|
34
|
+
# # /ipfs/1220142711d38ca7a33c5218416f8ffcc64648ca4616a625b5e0a0ab3da1911d5d7a
|
35
|
+
#
|
36
|
+
# @example Reading out the hash data
|
37
|
+
#
|
38
|
+
# location = '/ipfs/1220142711d38ca7a33c5218416f8ffcc64648ca4616a625b5e0a0ab3da1911d5d7a'
|
39
|
+
# hash = location.rpartition('/').last
|
40
|
+
# out = Multihashes.decode [hash].pack('H*')
|
41
|
+
# # => {:code=>18, :hash_function=>"sha2-256", :length=>32, :digest=>"\x14'\x11\xD3\x8C\xA7\xA3<R\x18Ao\x8F\xFC\xC6FH\xCAF\x16\xA6%\xB5\xE0\xA0\xAB=\xA1\x 91\x1D]z"}
|
42
|
+
#
|
43
|
+
module ContentAddressable
|
44
|
+
|
45
|
+
MULTIHASH_LOOKUP = {
|
46
|
+
md5: 'md5',
|
47
|
+
sha1: 'sha1',
|
48
|
+
sha256: 'sha2-256',
|
49
|
+
sha512: 'sha2-512'
|
50
|
+
}.freeze
|
51
|
+
|
52
|
+
def self.configure(uploader, opts = {})
|
53
|
+
uploader.opts[:content_addressable_hash] = opts.fetch(:hash, uploader.opts[:content_addressable_hash])
|
54
|
+
uploader.opts[:content_addressable_multihash] = opts.fetch(:multihash, uploader.opts[:content_addressable_multihash])
|
55
|
+
uploader.opts[:content_addressable_prefix] = opts.fetch(:prefix, uploader.opts[:content_addressable_prefix])
|
56
|
+
end
|
57
|
+
|
58
|
+
module InstanceMethods
|
59
|
+
def content_addressable_hash
|
60
|
+
(opts[:content_addressable_hash] || 'sha256').to_sym
|
61
|
+
end
|
62
|
+
|
63
|
+
def content_addressable_multihash
|
64
|
+
String(
|
65
|
+
opts[:content_addressable_multihash] ||
|
66
|
+
MULTIHASH_LOOKUP.fetch(content_addressable_hash)
|
67
|
+
)
|
68
|
+
end
|
69
|
+
|
70
|
+
def content_addressable_hex(io)
|
71
|
+
digest = calculate_signature(io, content_addressable_hash, format: :none)
|
72
|
+
Multihashes.encode(digest, content_addressable_multihash)
|
73
|
+
.unpack('H*')
|
74
|
+
.first
|
75
|
+
end
|
76
|
+
|
77
|
+
def generate_location(io, _)
|
78
|
+
[opts[:content_addressable_prefix], content_addressable_hex(io)].compact.join('/')
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
register_plugin(:content_addressable, ContentAddressable)
|
84
|
+
end
|
85
|
+
end
|
@@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = 'shrine-content_addressable'
|
8
|
-
spec.version = '0.3.
|
8
|
+
spec.version = '0.3.1'
|
9
9
|
spec.authors = ['Derk-Jan Karrenbeld']
|
10
10
|
spec.email = ['derk-jan+github@karrenbeld.info']
|
11
11
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shrine-content_addressable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Derk-Jan Karrenbeld
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-06-
|
11
|
+
date: 2018-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multihashes
|