Created
May 1, 2015 02:10
-
-
Save anonymous/e04307acb68d7f12f3c3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
require 'digest/sha1' | |
require 'zlib' | |
$objects = {} | |
class Blob | |
def initialize(content) | |
header = "blob #{content.length}\0" | |
stored_content = header + content | |
sha1 = Digest::SHA1.hexdigest(stored_content) | |
@compressed_content = Zlib::Deflate.deflate(stored_content) | |
@path = ".git/objects" + sha1[0..1] + "/" + sha1[2..-1] | |
puts sha1 | |
return sha1 | |
end | |
def save | |
$objects[@path.to_sym] = @compressed_content | |
end | |
end | |
content = "some text in a file" | |
blob = Blob.new(content) | |
blob.save |
This file contains hidden or 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
class Tree | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment