Skip to content

os: add Root.ReadFile & Root.WriteFile #73126

Closed
@neild

Description

@neild

I propose adding ReadFile and WriteFile methods to *os.Root:

package os

// ReadFile reads the named file in the root and returns the contents.
// See [ReadFile] for more details.
func (r *Root) ReadFile(name string) ([]byte, error)

// WriteFile writes data to the named file in the root, creating it if necessary.
// See [WriteFile] for more details.
func (r *Root) WriteFile(name string, data []byte, perm FileMode) error

These are purely convenience functions (as are os.ReadFile and os.WriteFile). I propose adding them because:

  1. os.ReadFile and os.WriteFile are very convenient convenience functions, and it's a shame not to have an equivalent that works with os.Root.
  2. The io/fs package not only includes a ReadFile convenience function, it includes a ReadFileFS variant of FS containing a ReadFile method. I think that points at this being something we consider core filesystem functionality.

Metadata

Metadata

Assignees

No one assigned

    Labels

    LibraryProposalIssues describing a requested change to the Go standard library or x/ libraries, but not to a toolProposalProposal-Accepted

    Type

    No type

    Projects

    Status

    Accepted

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions