Sha256: 2cf9df5089c8138f7d9533b166e3ed21b76fe673ff211a8e1d16bf9add041b15

Contents?: true

Size: 602 Bytes

Versions: 9

Compression:

Stored size: 602 Bytes

Contents

require 'linguist/blob_helper'
require 'rugged'

module Linguist
  class LazyBlob
    include BlobHelper

    MAX_SIZE = 128 * 1024

    attr_reader :repository
    attr_reader :oid
    attr_reader :name
    attr_reader :mode

    def initialize(repo, oid, name, mode = nil)
      @repository = repo
      @oid = oid
      @name = name
      @mode = mode
    end

    def data
      load_blob!
      @data
    end

    def size
      load_blob!
      @size
    end

    protected
    def load_blob!
      @data, @size = Rugged::Blob.to_buffer(repository, oid, MAX_SIZE) if @data.nil?
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
github-linguist-3.1.5 lib/linguist/lazy_blob.rb
github-linguist-3.1.4 lib/linguist/lazy_blob.rb
github-linguist-3.1.2 lib/linguist/lazy_blob.rb
github-linguist-3.1.1 lib/linguist/lazy_blob.rb
github-linguist-3.1.0 lib/linguist/lazy_blob.rb
github-linguist-3.0.3 lib/linguist/lazy_blob.rb
github-linguist-3.0.0 lib/linguist/lazy_blob.rb
github-linguist-3.0.0b2 lib/linguist/lazy_blob.rb
github-linguist-3.0.0b0 lib/linguist/lazy_blob.rb