code: func applyLayerHandler(dest string, layer io.Reader, options *archive.TarOptions, decompress bool) (size int64, err error) {
  	dest = filepath.Clean(dest)
  	if decompress {
  		decompressed, err := archive.DecompressStream(layer)
  		if err != nil {
  			return 0, err
  		}
  		defer decompressed.Close()
  
  		layer = decompressed
  	}
  	if options == nil {
  		options = &archive.TarOptions{}
  		if rsystem.RunningInUserNS() {
  			options.InUserNS = true
  		}
  	}
  	if options.ExcludePatterns == nil {
  		options.ExcludePatterns = []string{}
  	}
  
  	data, err := json.Marshal(options)
  	if err != nil {
  		return 0, fmt.Errorf("ApplyLayer json encode: %v", err)
  	}
  
  	cmd := reexec.Command("docker-applyLayer", dest)
  	cmd.Stdin = layer
  	cmd.Env = append(cmd.Env, fmt.Sprintf("OPT=%s", data))
  
  	outBuf, errBuf := new(bytes.Buffer), new(bytes.Buffer)
  	cmd.Stdout, cmd.Stderr = outBuf, errBuf
  
  	if err = cmd.Run(); err != nil {
  		return 0, fmt.Errorf("ApplyLayer %s stdout: %s stderr: %s", err, outBuf, errBuf)
  	}
  
  	// Stdout should be a valid JSON struct representing an applyLayerResponse.
  	response := applyLayerResponse{}
  	decoder := json.NewDecoder(outBuf)
  	if err = decoder.Decode(&response); err != nil {
  		return 0, fmt.Errorf("unable to decode ApplyLayer JSON response: %s", err)
  	}
  
  	return response.LayerSize, nil
  }
docs: // applyLayerHandler parses a diff in the standard layer format from `layer`, and
  // applies it to the directory `dest`. Returns the size in bytes of the
  // contents of the layer.