// Create a new Header for file "example.txt" h := &tar.Header{ Name: "example.txt", Size: fileInfo.Size(), Mode: int64(fileInfo.Mode()), ModTime: fileInfo.ModTime(), } // Write the Header to the tar archive err = tw.WriteHeader(h) if err != nil { log.Fatal(err) }
// Get information about a file fileInfo, err := os.Stat("example.txt") if err != nil { log.Fatal(err) } // Print the file size fmt.Println("File size:", fileInfo.Size())In both examples, the package library is "archive/tar".