Add `&`/`.sha256` to stay compliant with spec

This commit is contained in:
Netscape Navigator 2019-09-22 06:04:23 -05:00
parent 7da80941c5
commit 87685efb60
1 changed files with 6 additions and 2 deletions

View File

@ -7,6 +7,9 @@ module Pigeon
CONF_DIR = "conf"
BLOB_DIR = "blobs"
BLOB_HEADER = "&"
BLOB_FOOTER = ".sha256"
def self.current
@current ||= self.new
end
@ -33,13 +36,14 @@ module Pigeon
path = blob_path_for(hex_digest)
File.write(path, data)
hex_digest
[BLOB_HEADER, hex_digest, BLOB_FOOTER].join("")
end
def get_blob(hex_digest)
hd = hex_digest.gsub(BLOB_HEADER, "").gsub(BLOB_FOOTER, "")
# Allows user to pass first n chars of a
# hash instead of the whole hash.
f = Dir[blob_path_for(hex_digest) + "*"].first
f = Dir[blob_path_for(hd) + "*"].first
File.file?(f) ? File.read(f) : nil
end