// 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 fsimport// ReadFileFS is the interface implemented by a file system// that provides an optimized implementation of ReadFile.typeReadFileFSinterface {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 {returnnil, }defer .Close()varintif , := .Stat(); == nil { := .Size()ifint64(int()) == { = int() } } := make([]byte, 0, +1)for {iflen() >= cap() { := append([:cap()], 0) = [:len()] } , := .Read([len():cap()]) = [:len()+]if != nil {if == io.EOF { = nil }return , } }}
The pages are generated with Goldsv0.6.7. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.