func Apply(ctx context.Context, root string, r io.Reader, opts ...ApplyOpt) (int64, error) {
	root = filepath.Clean(root)
	var options ApplyOptions
	for _, opt := range opts {
		if err := opt(&options); err != nil {
			return 0, errors.Wrap(err, "failed to apply option")
		}
	}
	if options.Filter == nil {
		options.Filter = all
	}
	if options.applyFunc == nil {
		options.applyFunc = applyNaive
	}
	return options.applyFunc(ctx, root, r, options)
}
Apply applies a tar stream of an OCI style diff tar.
See https://github.com/opencontainers/image-spec/blob/master/layer.md#applying-changesets
package archive
import (
	"archive/tar"
	"context"
	"io"
	"os"
	"path/filepath"
	"runtime"
	"strings"
	"sync"
	"syscall"
	"time"
	"github.com/containerd/containerd/log"
	"github.com/containerd/continuity/fs"
	"github.com/pkg/errors"
)
var bufPool = &sync.Pool{
	New: func() interface{} {
		buffer := make([]byte, 32*1024)
		return &buffer
	},
}
var errInvalidArchive = errors.New("invalid archive")
func Diff(ctx context.Context, a, b string) io.ReadCloser {
	r, w := io.Pipe()
	go func() {
		err := WriteDiff(ctx, w, a, b)
		if err = w.CloseWithError(err); err != nil {
			log.G(ctx).WithError(err).Debugf("closing tar pipe failed")
		}
	}()
	return r
}
func WriteDiff(ctx context.Context, w io.Writer, a, b string, opts ...WriteDiffOpt) error {
	var options WriteDiffOptions
	for _, opt := range opts {
		if err := opt(&options); err != nil {
			return errors.Wrap(err, "failed to apply option")
		}
	}
	if options.writeDiffFunc == nil {
		options.writeDiffFunc = writeDiffNaive
	}
	return options.writeDiffFunc(ctx, w, a, b, options)
}
func writeDiffNaive(ctx context.Context, w io.Writer, a, b string, _ WriteDiffOptions) error {
	cw := newChangeWriter(w, b)
	err := fs.Changes(ctx, a, b, cw.HandleChange)
	if err != nil {
		return errors.Wrap(err, "failed to create diff tar stream")
	}
	return cw.Close()
}
const (
	whiteoutPrefix = ".wh."
	whiteoutMetaPrefix = whiteoutPrefix + whiteoutPrefix
	whiteoutOpaqueDir = whiteoutMetaPrefix + ".opq"
	paxSchilyXattr = "SCHILY.xattr."
)