Skip to content

proposal: x/tools/txtar: add Extract function or method #61386

Closed
@adonovan

Description

@adonovan

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions