code: func archiveWrite(u *url.URL, tw *tar.Writer) error {
  	info, err := os.Stat(u.Path)
  	if err != nil {
  		return err
  	}
  
  	// Note that the VMX will trim any trailing slash.  For example:
  	// "/foo/bar/?prefix=bar/" will end up here as "/foo/bar/?prefix=bar"
  	// Escape to avoid this: "/for/bar/?prefix=bar%2F"
  	prefix := u.Query().Get("prefix")
  
  	dir := u.Path
  
  	f := func(file string, fi os.FileInfo, err error) error {
  		if err != nil {
  			return filepath.SkipDir
  		}
  
  		name := strings.TrimPrefix(file, dir)
  		name = strings.TrimPrefix(name, "/")
  
  		if name == "" {
  			return nil // this is u.Path itself (which may or may not have a trailing "/")
  		}
  
  		if prefix != "" {
  			name = prefix + name
  		}
  
  		header, _ := tar.FileInfoHeader(fi, name)
  
  		header.Name = name
  
  		if header.Typeflag == tar.TypeDir {
  			header.Name += "/"
  		}
  
  		var f *os.File
  
  		if header.Typeflag == tar.TypeReg && fi.Size() != 0 {
  			f, err = os.Open(filepath.Clean(file))
  			if err != nil {
  				if os.IsPermission(err) {
  					return nil
  				}
  				return err
  			}
  		}
  
  		_ = tw.WriteHeader(header)
  
  		if f != nil {
  			_, err = io.Copy(tw, f)
  			_ = f.Close()
  		}
  
  		return err
  	}
  
  	if info.IsDir() {
  		return filepath.Walk(u.Path, f)
  	}
  
  	dir = filepath.Dir(dir)
  
  	return f(u.Path, info, nil)
  }
docs: // archiveWrite writes the contents of the given source directory to the given tar.Writer.