Last active
June 10, 2020 00:15
-
-
Save shtukas/58efe5d812dd3fc66d8cedbaf6ce8682 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/Users/pascal/.rvm/rubies/ruby-2.5.1/bin/ruby | |
# encoding: UTF-8 | |
require 'digest/sha1' | |
require "/Users/pascal/Galaxy/LucilleOS/Libraries/Ruby-Libraries/KeyValueStore.rb" | |
=begin | |
KeyValueStore::setFlagTrue(repositorylocation, key) | |
KeyValueStore::setFlagFalse(repositorylocation, key) | |
KeyValueStore::flagIsTrue(repositorylocation, key) | |
KeyValueStore::set(repositorylocation or nil, key, value) | |
KeyValueStore::getOrNull(repositorylocation or nil, key) | |
KeyValueStore::getOrDefaultValue(repositorylocation or nil, key, defaultValue) | |
KeyValueStore::destroy(repositorylocation or nil, key) | |
=end | |
require "/Users/pascal/Galaxy/LucilleOS/Libraries/Ruby-Libraries/AionCore.rb" | |
# -------------------------------------------------------------------- | |
class Elizabeth | |
def initialize() | |
end | |
def commitBlob(blob) | |
nhash = "SHA256-#{Digest::SHA256.hexdigest(blob)}" | |
KeyValueStore::set(nil, "SHA256-#{Digest::SHA256.hexdigest(blob)}", blob) | |
nhash | |
end | |
def filepathToHash(filepath) | |
"SHA256-#{Digest::SHA256.file(filepath).hexdigest}" | |
end | |
def readBlobErrorIfNotFound(nhash) | |
blob = KeyValueStore::getOrNull(nil, nhash) | |
raise "[Elizabeth error: fc1dd1aa]" if blob.nil? | |
blob | |
end | |
def datablobCheck(nhash) | |
begin | |
readBlobErrorIfNotFound(nhash) | |
true | |
rescue | |
false | |
end | |
end | |
end | |
def dataToHash(data) | |
Digest::SHA1.hexdigest(data) | |
end | |
def put(data) | |
xhash = dataToHash(data) | |
KeyValueStore::set(nil, xhash, data) | |
xhash | |
end | |
def get(xhash) | |
KeyValueStore::getOrNull(nil, xhash) | |
end | |
if ARGV[0] == "put" then | |
data = STDIN.gets() | |
puts put(data) | |
end | |
if ARGV[0] == "get" and ARGV[1] then | |
xhash = ARGV[1] | |
puts get(xhash) | |
end | |
if ARGV[0] == "commit" and ARGV[1] then | |
location = ARGV[1] | |
xhash = AionCore::commitLocationReturnHash(Elizabeth.new(), location) | |
puts "#{Time.new.to_s} | #{xhash}" | |
end | |
if ARGV[0] == "export" and ARGV[1] and ARGV[2] then | |
nhash = ARGV[1] | |
targetReconstructionFolderpath = ARGV[2] | |
AionCore::exportHashAtFolder(Elizabeth.new(), nhash, targetReconstructionFolderpath) | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment