module Shrine::Plugins::ContentAddressable
plugin :signature plugin :content_addressable
This plugin uses the {Signature} plugin to turn the content into a content
addressable, which simply means the digest of the content is now the location, and location the file by digest becomes possible.
The results are wrapped in a multihash, so you may change your hashing
method in production, whilst not losing access to the old hashes. This works by adding metadata to the hash of what function was used. https://github.com/multiformats/multihash
@example Setup the plugin using sha256
plugin :content_addressable, hash: :sha256 # /1220142711d38ca7a33c5218416f8ffcc64648ca4616a625b5e0a0ab3da1911d5d7a
@example You can also prefix the final location, for example to make the
location ready for IPFS https://ipfs.io/ plugin :content_addressable, hash: :sha256, prefix: 'ipfs' # /ipfs/1220142711d38ca7a33c5218416f8ffcc64648ca4616a625b5e0a0ab3da1911d5d7a
@example Reading out the hash data
location = '/ipfs/1220142711d38ca7a33c5218416f8ffcc64648ca4616a625b5e0a0ab3da1911d5d7a' hash = location.rpartition('/').last out = Multihashes.decode [hash].pack('H*') # => {: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"}
Constants
- MULTIHASH_LOOKUP
Public Class Methods
configure(uploader, opts = {})
click to toggle source
# File lib/shrine/plugins/content_addressable.rb, line 54 def self.configure(uploader, opts = {}) uploader.opts[:content_addressable_hash] = opts.fetch(:hash, uploader.opts[:content_addressable_hash]) uploader.opts[:content_addressable_multihash] = opts.fetch(:multihash, uploader.opts[:content_addressable_multihash]) uploader.opts[:content_addressable_prefix] = opts.fetch(:prefix, uploader.opts[:content_addressable_prefix]) end