Welcome to mirror list, hosted at ThFree Co, Russian Federation.

lfs_pointer_file.rb « git « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: efd84e30ad9190b03c9b3af47511dca1b269f038 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# frozen_string_literal: true

module Gitlab
  module Git
    class LfsPointerFile
      VERSION = "https://git-lfs.github.com/spec/v1"
      VERSION_LINE = "version #{VERSION}"

      def initialize(data)
        @data = data
      end

      def pointer
        @pointer ||= <<~FILE
          #{VERSION_LINE}
          oid sha256:#{sha256}
          size #{size}
        FILE
      end

      def size
        @size ||= @data.bytesize
      end

      def sha256
        @sha256 ||= Digest::SHA256.hexdigest(@data)
      end

      def inspect
        "#<#{self.class}:#{object_id} @size=#{size}, @sha256=#{sha256.inspect}>"
      end
    end
  end
end