Some checks failed
cache-seeder / prune (push) Has been skipped
cache-seeder / frontend (push) Failing after 3s
cache-seeder / python (push) Failing after 3s
cache-seeder / gobuild (push) Failing after 4s
cache-seeder / lint (bindata, lint-backend) (push) Failing after 3s
giteabot backport / giteabot (push) Has been skipped
giteabot / giteabot (push) Has been skipped
cache-prune / prune (push) Has been skipped
release-nightly-snapcraft / build-and-publish (ubuntu-24.04) (push) Has been cancelled
release-nightly-snapcraft / build-and-publish (ubuntu-24.04-arm) (push) Has been cancelled
release-nightly / nightly-binary (push) Has been cancelled
release-nightly / nightly-container (push) Has been cancelled
cron-renovate / cron-renovate (push) Has been skipped
48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
// Copyright 2015 The Gogs Authors. All rights reserved.
|
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
//go:build gogit
|
|
|
|
package git
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
|
|
"gitea.dev/modules/log"
|
|
|
|
"github.com/go-git/go-git/v5/plumbing"
|
|
)
|
|
|
|
// Blob represents a Git object.
|
|
type Blob struct {
|
|
ID ObjectID
|
|
repo *Repository
|
|
name string
|
|
}
|
|
|
|
func (b *Blob) gogitEncodedObj() (plumbing.EncodedObject, error) {
|
|
return b.repo.gogitRepo.Storer.EncodedObject(plumbing.AnyObject, plumbing.Hash(b.ID.RawValue()))
|
|
}
|
|
|
|
// DataAsync gets a ReadCloser for the contents of a blob without reading it all.
|
|
// Calling the Close function on the result will discard all unread output.
|
|
func (b *Blob) DataAsync(_ context.Context) (io.ReadCloser, error) {
|
|
obj, err := b.gogitEncodedObj()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return obj.Reader()
|
|
}
|
|
|
|
// Size returns the uncompressed size of the blob
|
|
func (b *Blob) Size(_ context.Context) int64 {
|
|
obj, err := b.gogitEncodedObj()
|
|
if err != nil {
|
|
log.Error("Error getting gogit encoded object for blob %s(%s): %v", b.name, b.ID.String(), err)
|
|
return 0
|
|
}
|
|
return obj.Size()
|
|
}
|