return f, nil
}
+// The ReadFile method calls the [ReadFile] function for the file
+// with the given name in the directory. The function provides
+// robust handling for small files and special file systems.
+// Through this method, dirFS implements [io/fs.ReadFileFS].
+func (dir dirFS) ReadFile(name string) ([]byte, error) {
+ fullname, err := dir.join(name)
+ if err != nil {
+ return nil, &PathError{Op: "readfile", Path: name, Err: err}
+ }
+ return ReadFile(fullname)
+}
+
func (dir dirFS) Stat(name string) (fs.FileInfo, error) {
fullname, err := dir.join(name)
if err != nil {
}
}
+func TestDirFSReadFileProc(t *testing.T) {
+ t.Parallel()
+
+ fsys := DirFS("/")
+ name := "proc/sys/fs/pipe-max-size"
+ if _, err := fs.Stat(fsys, name); err != nil {
+ t.Skip()
+ }
+ data, err := fs.ReadFile(fsys, name)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if len(data) == 0 || data[len(data)-1] != '\n' {
+ t.Fatalf("read %s: not newline-terminated: %q", name, data)
+ }
+}
+
func TestWriteStringAlloc(t *testing.T) {
if runtime.GOOS == "js" {
t.Skip("js allocates a lot during File.WriteString")