repository: move Blob, Blobs and PackedBlob to pack package

This removes them from the public interface. The latter now only
provides the PackBlob interface, without being bound to the type used
internally by the pack package.
This commit is contained in:
Michael Eischer
2026-06-13 18:58:37 +02:00
parent 35af104749
commit c062a78dcd
27 changed files with 373 additions and 345 deletions
-58
View File
@@ -1,46 +1,11 @@
package restic
import (
"cmp"
"fmt"
"slices"
"github.com/restic/restic/internal/crypto"
"github.com/restic/restic/internal/errors"
)
// Blob is one part of a file or a tree.
type Blob struct {
BlobHandle
Length uint
Offset uint
UncompressedLength uint
}
func (b Blob) String() string {
return fmt.Sprintf("<Blob (%v) %v, offset %v, length %v, uncompressed length %v>",
b.Type, b.ID.Str(), b.Offset, b.Length, b.UncompressedLength)
}
func (b Blob) DataLength() uint {
if b.UncompressedLength != 0 {
return b.UncompressedLength
}
return uint(crypto.PlaintextLength(int(b.Length)))
}
func (b Blob) IsCompressed() bool {
return b.UncompressedLength != 0
}
type Blobs []Blob
func (b Blobs) Sort() {
slices.SortFunc(b, func(a, b Blob) int {
return cmp.Compare(a.Offset, b.Offset)
})
}
// PackBlob is one index entry for a blob in a pack file.
// The interface intentionally omits the offset at which a blob is stored in the pack.
// This ensures that pack file internals are not leaked.
@@ -54,29 +19,6 @@ type PackBlob interface {
IsCompressed() bool
}
// PackedBlob is a blob stored within a file.
type PackedBlob struct {
Blob
PackID ID
}
type packBlob struct {
PackedBlob
}
func (pb packBlob) PackID() ID { return pb.PackedBlob.PackID }
func (pb packBlob) Handle() BlobHandle { return pb.BlobHandle }
func (pb packBlob) CiphertextLength() uint { return pb.Length }
func (pb packBlob) PlaintextLength() uint { return pb.DataLength() }
func (pb packBlob) IsCompressed() bool { return pb.Blob.IsCompressed() }
// AsPackBlob returns a PackBlob view of a PackedBlob.
func AsPackBlob(pb PackedBlob) PackBlob { return packBlob{pb} }
// BlobHandle identifies a blob of a given type.
type BlobHandle struct {
ID ID
-19
View File
@@ -3,8 +3,6 @@ package restic
import (
"encoding/json"
"testing"
rtest "github.com/restic/restic/internal/test"
)
var blobTypeJSON = []struct {
@@ -41,20 +39,3 @@ func TestBlobTypeJSON(t *testing.T) {
}
}
}
func TestBlobsSort(t *testing.T) {
blobs := Blobs{
{Offset: 100},
{Offset: 0},
{Offset: 50},
}
blobs.Sort()
rtest.Equals(t, uint(0), blobs[0].Offset)
rtest.Equals(t, uint(50), blobs[1].Offset)
rtest.Equals(t, uint(100), blobs[2].Offset)
}
func TestBlobsSortNilSlice(t *testing.T) {
var blobs Blobs
blobs.Sort()
}
-5
View File
@@ -124,11 +124,6 @@ type SaverRemoverUnpacked[FT FileTypes] interface {
RemoverUnpacked[FT]
}
type PackBlobs struct {
PackID ID
Blobs Blobs
}
type TerminalCounterFactory interface {
// NewCounterTerminalOnly returns a new progress counter that is only shown if stdout points to a
// terminal. It is not shown if --quiet or --json is specified.