func Untar(
	ctx context.Context,
	reader io.Reader,
	writeBucket storage.WriteBucket,
	mapper storage.Mapper,
	stripComponentCount uint32,
) error {
	tarReader := tar.NewReader(reader)
	walkChecker := storageutil.NewWalkChecker()
	for tarHeader, err := tarReader.Next(); err != io.EOF; tarHeader, err = tarReader.Next() {
		if err != nil {
			return err
		}
		if err := walkChecker.Check(ctx); err != nil {
			return err
		}
		path, ok, err := unmapArchivePath(tarHeader.Name, mapper, stripComponentCount)
		if err != nil {
			return err
		}
		if !ok {
			continue
		}
		if tarHeader.FileInfo().Mode().IsRegular() {
			if tarHeader.Size < 0 {
				return fmt.Errorf("invalid size for tar file %s: %d", tarHeader.Name, tarHeader.Size)
			}
			if err := storage.CopyReader(ctx, writeBucket, tarReader, path); err != nil {
				return err
			}
		}
	}
	return nil
}
// Untar untars the given tar archive from the reader into the bucket.
//
// Only regular files are added to the bucket.
//
// Paths from the tar archive will be mapped before adding to the bucket.
// Mapper can be nil.
// StripComponents happens before the mapper.
Untar untars the given tar archive from the reader into the bucket.

Only regular files are added to the bucket.

Paths from the tar archive will be mapped before adding to the bucket.
Mapper can be nil.
StripComponents happens before the mapper.
// Untar untars the given tar archive from the reader into the bucket . // // Only regular files are added to the bucket . // // Paths from the tar archive will be mapped before adding to the bucket . // Mapper can be nil . // StripComponents happens before the mapper .
func Untar(
	ctx context.Context,
	reader io.Reader,
	writeBucket storage.WriteBucket,
	mapper storage.Mapper,
	stripComponentCount uint32,
) error {
	tarReader := tar.NewReader(reader)
	walkChecker := storageutil.NewWalkChecker()
	for tarHeader, err := tarReader.Next(); err != io.EOF; tarHeader, err = tarReader.Next() {
		if err != nil {
			return err
		}
		if err := walkChecker.Check(ctx); err != nil {
			return err
		}
		path, ok, err := unmapArchivePath(tarHeader.Name, mapper, stripComponentCount)
		if err != nil {
			return err
		}
		if !ok {
			continue
		}
		if tarHeader.FileInfo().Mode().IsRegular() {
			if tarHeader.Size < 0 {
				return fmt.Errorf("invalid size for tar file %s: %d", tarHeader.Name, tarHeader.Size)
			}
			if err := storage.CopyReader(ctx, writeBucket, tarReader, path); err != nil {
				return err
			}
		}
	}
	return nil
}
func Untar ( ctx context . Context , reader io . Reader , writeBucket storage . WriteBucket , mapper storage . Mapper , stripComponentCount uint32 , ) error { tarReader := tar . NewReader ( reader ) walkChecker := storageutil . NewWalkChecker ( ) for tarHeader , err := tarReader . Next ( ) ; err != io . EOF ; tarHeader , err = tarReader . Next ( ) { if err != nil { return err } if err := walkChecker . Check ( ctx ) ; err != nil { return err } path , ok , err := unmapArchivePath ( tarHeader . Name , mapper , stripComponentCount ) if err != nil { return err } if ! ok { continue } if tarHeader . FileInfo ( ) . Mode ( ) . IsRegular ( ) { if tarHeader . Size < 0 { return fmt . Errorf ( " " , tarHeader . Name , tarHeader . Size ) } if err := storage . CopyReader ( ctx , writeBucket , tarReader , path ) ; err != nil { return err } } } return nil }
Untar untars the given tar archive from the reader into the bucket.
Untar untars the given tar archive from the reader into the bucket .