// Copyright 2020 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package fs

import 

// ReadFileFS is the interface implemented by a file system
// that provides an optimized implementation of [ReadFile].
type ReadFileFS interface {
	FS

	// ReadFile reads the named file and returns its contents.
	// A successful call returns a nil error, not io.EOF.
	// (Because ReadFile reads the whole file, the expected EOF
	// from the final Read is not treated as an error to be reported.)
	//
	// The caller is permitted to modify the returned byte slice.
	// This method should return a copy of the underlying data.
	ReadFile(name string) ([]byte, error)
}

// ReadFile reads the named file from the file system fs and returns its contents.
// A successful call returns a nil error, not [io.EOF].
// (Because ReadFile reads the whole file, the expected EOF
// from the final Read is not treated as an error to be reported.)
//
// If fs implements [ReadFileFS], ReadFile calls fs.ReadFile.
// Otherwise ReadFile calls fs.Open and uses Read and Close
// on the returned [File].
func ( FS,  string) ([]byte, error) {
	if ,  := .(ReadFileFS);  {
		return .ReadFile()
	}

	,  := .Open()
	if  != nil {
		return nil, 
	}
	defer .Close()

	var  int
	if ,  := .Stat();  == nil {
		 := .Size()
		if int64(int()) ==  {
			 = int()
		}
	}

	 := make([]byte, 0, +1)
	for {
		if len() >= cap() {
			 := append([:cap()], 0)
			 = [:len()]
		}
		,  := .Read([len():cap()])
		 = [:len()+]
		if  != nil {
			if  == io.EOF {
				 = nil
			}
			return , 
		}
	}
}