34 lines
614 B
Go
34 lines
614 B
Go
//go:build e2e
|
|
|
|
package e2e
|
|
|
|
import (
|
|
"archive/tar"
|
|
"errors"
|
|
"io"
|
|
"strings"
|
|
)
|
|
|
|
// firstFileInTar returns the contents of the first regular file in an archive
|
|
// produced by the Docker archive API.
|
|
func firstFileInTar(r io.Reader) (string, error) {
|
|
tr := tar.NewReader(r)
|
|
for {
|
|
hdr, err := tr.Next()
|
|
if errors.Is(err, io.EOF) {
|
|
return "", errors.New("archive contains no regular file")
|
|
}
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
if hdr.Typeflag != tar.TypeReg {
|
|
continue
|
|
}
|
|
var b strings.Builder
|
|
if _, err := io.Copy(&b, tr); err != nil {
|
|
return "", err
|
|
}
|
|
return b.String(), nil
|
|
}
|
|
}
|