Standard library / archive/tar
archive/tar.FileInfoNames
Extends fs.FileInfo with Uname and Gname methods to supply textual ownership metadata without host lookup. Expected stdout: 'learner lab\n'.
Formal Syntax & Structure
go syntaxgo
type FileInfoNames interface { fs.FileInfo Uname() (string, error) Gname() (string, error)}Working Example
Example Snippetgo
package main
import ( "archive/tar" "fmt" "io/fs" "testing/fstest")
func must(e error) { if e != nil { panic(e) }}
type info struct{ fs.FileInfo }
func (info) Uname() (string, error) { return "learner", nil }func (info) Gname() (string, error) { return "lab", nil }func main() { fi, e := fs.Stat(fstest.MapFS{"a": &fstest.MapFile{}}, "a") must(e) var named tar.FileInfoNames = info{fi} h, e := tar.FileInfoHeader(named, "") must(e) fmt.Println(h.Uname, h.Gname)}