Skip to content

Instantly share code, notes, and snippets.

Created May 1, 2015 02:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/e04307acb68d7f12f3c3 to your computer and use it in GitHub Desktop.
Save anonymous/e04307acb68d7f12f3c3 to your computer and use it in GitHub Desktop.
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
class Tree
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment