`blob get`

This commit is contained in:
Netscape Navigator 2019-09-22 06:00:19 -05:00
parent f9b9636238
commit 7da80941c5
4 changed files with 18 additions and 9 deletions

View File

@ -17,7 +17,7 @@ Eg: `pigeon identity show` becomes `./pigeon-cli show`.
- [X] pigeon identity show
- [X] pigeon blob set
- [ ] pigeon blob get
- [X] pigeon blob get
- [ ] pigeon message new
- [ ] pigeon message current

View File

@ -36,7 +36,7 @@ module Pigeon
public_key: public_key,
private_key: private_key,
}.map do |k, v|
Pigeon::Storage.current.save_conf(k, v)
Pigeon::Storage.current.set_conf(k, v)
end
end
end

View File

@ -19,7 +19,7 @@ module Pigeon
end
end
def save_conf(key, value)
def set_conf(key, value)
path = conf_path_for(key)
File.write(path, value.to_s)
end
@ -29,10 +29,19 @@ module Pigeon
end
def set_blob(data)
hash = Digest::SHA256.hexdigest(data)
path = blob_path_for(hash)
hex_digest = Digest::SHA256.hexdigest(data)
path = blob_path_for(hex_digest)
File.write(path, data)
hex_digest
end
def get_blob(hex_digest)
# Allows user to pass first n chars of a
# hash instead of the whole hash.
f = Dir[blob_path_for(hex_digest) + "*"].first
File.file?(f) ? File.read(f) : nil
end
def initialized?

View File

@ -35,13 +35,13 @@ module Pigeon
desc "set", "Copy arbitrary binary data into the roost"
def set(data)
Pigeon::Storage.current.set_blob(data)
puts Pigeon::Storage.current.set_blob(data)
end
desc "get", "Read arbitrary data from the roost"
def get
raise "WIP"
def get(hex_digest)
puts Pigeon::Storage.current.get_blob(hex_digest)
end
end