diff options
Diffstat (limited to 'internal/pkg/tar.go')
| -rw-r--r-- | internal/pkg/tar.go | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/internal/pkg/tar.go b/internal/pkg/tar.go index 624eafe2..0aa8e3bf 100644 --- a/internal/pkg/tar.go +++ b/internal/pkg/tar.go @@ -6,6 +6,7 @@ import ( "compress/gzip" "encoding/binary" "errors" + "fmt" "io" "io/fs" "net/http" @@ -32,11 +33,29 @@ type tarArtifact struct { compression uint64 } +// tarArtifactNamed embeds tarArtifact for a [fmt.Stringer] tarball. +type tarArtifactNamed struct { + tarArtifact + // Copied from tarArtifact.f. + name string +} + +var _ fmt.Stringer = new(tarArtifactNamed) + +// String returns the name of the underlying [Artifact] suffixed with unpack. +func (a *tarArtifactNamed) String() string { return a.name + "-unpack" } + // NewTar returns a new [Artifact] backed by the supplied [Artifact] and // compression method. The source [Artifact] must be compatible with // [TContext.Open]. func NewTar(a Artifact, compression uint64) Artifact { - return &tarArtifact{a, compression} + ta := tarArtifact{a, compression} + if s, ok := a.(fmt.Stringer); ok { + if name := s.String(); name != "" { + return &tarArtifactNamed{ta, name} + } + } + return &ta } // NewHTTPGetTar is abbreviation for NewHTTPGet passed to NewTar. |
