Closed
Description
While developing tests, I've written this function at least four times this week:
package txtar
// Extract writes each file in the archive to the corresponding location beneath dir.
func Extract(ar *Archive, dir string) error {
for _, file := range ar.Files {
name := filepath.Join(dir, file.Name)
if err := os.MkdirAll(filepath.Dir(name), 0777); err != nil {
return err
}
if err := os.WriteFile(name, file.Data, 0666); err != nil {
return err
}
}
return nil
}
I propose that we add it to the txtar package, either as a function or a method of Archive.