class Envirobly::Aws::S3

def compress_and_upload_object(object_hash, chdir:)

def compress_and_upload_object(object_hash, chdir:)
  key = object_key object_hash
  Tempfile.create([ "envirobly-push", ".gz" ]) do |tempfile|
    gz = Zlib::GzipWriter.new(tempfile)
    Open3.popen3("git", "cat-file", "-p", object_hash, chdir:) do |_, stdout, stderr, thread|
      IO.copy_stream(stdout, gz)
      unless thread.value.success?
        raise "`git cat-file -p #{object_hash}` failed: #{stderr.read}"
      end
    ensure
      gz.close
    end
    @client.put_object(bucket: @bucket, body: tempfile, key:)
    # puts "⤴ #{key}"
  end
end