summaryrefslogtreecommitdiff
path: root/devdocs/go/io%2Ffs%2Findex.html
diff options
context:
space:
mode:
Diffstat (limited to 'devdocs/go/io%2Ffs%2Findex.html')
-rw-r--r--devdocs/go/io%2Ffs%2Findex.html256
1 files changed, 256 insertions, 0 deletions
diff --git a/devdocs/go/io%2Ffs%2Findex.html b/devdocs/go/io%2Ffs%2Findex.html
new file mode 100644
index 00000000..4b0094cb
--- /dev/null
+++ b/devdocs/go/io%2Ffs%2Findex.html
@@ -0,0 +1,256 @@
+<h1> Package fs </h1> <ul id="short-nav">
+<li><code>import "io/fs"</code></li>
+<li><a href="#pkg-overview" class="overviewLink">Overview</a></li>
+<li><a href="#pkg-index" class="indexLink">Index</a></li>
+<li><a href="#pkg-examples" class="examplesLink">Examples</a></li>
+</ul> <h2 id="pkg-overview">Overview </h2> <p>Package fs defines basic interfaces to a file system. A file system can be provided by the host operating system but also by other packages. </p>
+<p>See the <span>testing/fstest</span> package for support with testing implementations of file systems. </p> <h2 id="pkg-index">Index </h2> <ul id="manual-nav">
+<li><a href="#pkg-variables">Variables</a></li>
+<li><a href="#FormatDirEntry">func FormatDirEntry(dir DirEntry) string</a></li>
+<li><a href="#FormatFileInfo">func FormatFileInfo(info FileInfo) string</a></li>
+<li><a href="#Glob">func Glob(fsys FS, pattern string) (matches []string, err error)</a></li>
+<li><a href="#ReadFile">func ReadFile(fsys FS, name string) ([]byte, error)</a></li>
+<li><a href="#ValidPath">func ValidPath(name string) bool</a></li>
+<li><a href="#WalkDir">func WalkDir(fsys FS, root string, fn WalkDirFunc) error</a></li>
+<li><a href="#DirEntry">type DirEntry</a></li>
+<li> <a href="#FileInfoToDirEntry">func FileInfoToDirEntry(info FileInfo) DirEntry</a>
+</li>
+<li> <a href="#ReadDir">func ReadDir(fsys FS, name string) ([]DirEntry, error)</a>
+</li>
+<li><a href="#FS">type FS</a></li>
+<li> <a href="#Sub">func Sub(fsys FS, dir string) (FS, error)</a>
+</li>
+<li><a href="#File">type File</a></li>
+<li><a href="#FileInfo">type FileInfo</a></li>
+<li> <a href="#Stat">func Stat(fsys FS, name string) (FileInfo, error)</a>
+</li>
+<li><a href="#FileMode">type FileMode</a></li>
+<li> <a href="#FileMode.IsDir">func (m FileMode) IsDir() bool</a>
+</li>
+<li> <a href="#FileMode.IsRegular">func (m FileMode) IsRegular() bool</a>
+</li>
+<li> <a href="#FileMode.Perm">func (m FileMode) Perm() FileMode</a>
+</li>
+<li> <a href="#FileMode.String">func (m FileMode) String() string</a>
+</li>
+<li> <a href="#FileMode.Type">func (m FileMode) Type() FileMode</a>
+</li>
+<li><a href="#GlobFS">type GlobFS</a></li>
+<li><a href="#PathError">type PathError</a></li>
+<li> <a href="#PathError.Error">func (e *PathError) Error() string</a>
+</li>
+<li> <a href="#PathError.Timeout">func (e *PathError) Timeout() bool</a>
+</li>
+<li> <a href="#PathError.Unwrap">func (e *PathError) Unwrap() error</a>
+</li>
+<li><a href="#ReadDirFS">type ReadDirFS</a></li>
+<li><a href="#ReadDirFile">type ReadDirFile</a></li>
+<li><a href="#ReadFileFS">type ReadFileFS</a></li>
+<li><a href="#StatFS">type StatFS</a></li>
+<li><a href="#SubFS">type SubFS</a></li>
+<li><a href="#WalkDirFunc">type WalkDirFunc</a></li>
+</ul> <div id="pkg-examples"> <h3>Examples</h3> <dl> <dd><a class="exampleLink" href="#example_WalkDir">WalkDir</a></dd> </dl> </div> <h3>Package files</h3> <p> <span>format.go</span> <span>fs.go</span> <span>glob.go</span> <span>readdir.go</span> <span>readfile.go</span> <span>stat.go</span> <span>sub.go</span> <span>walk.go</span> </p> <h2 id="pkg-variables">Variables</h2> <p>Generic file system errors. Errors returned by file systems can be tested against these errors using <span>errors.Is</span>. </p>
+<pre data-language="go">var (
+ ErrInvalid = errInvalid() // "invalid argument"
+ ErrPermission = errPermission() // "permission denied"
+ ErrExist = errExist() // "file already exists"
+ ErrNotExist = errNotExist() // "file does not exist"
+ ErrClosed = errClosed() // "file already closed"
+)</pre> <p>SkipAll is used as a return value from <a href="#WalkDirFunc">WalkDirFunc</a> to indicate that all remaining files and directories are to be skipped. It is not returned as an error by any function. </p>
+<pre data-language="go">var SkipAll = errors.New("skip everything and stop the walk")</pre> <p>SkipDir is used as a return value from <a href="#WalkDirFunc">WalkDirFunc</a> to indicate that the directory named in the call is to be skipped. It is not returned as an error by any function. </p>
+<pre data-language="go">var SkipDir = errors.New("skip this directory")</pre> <h2 id="FormatDirEntry">func <span>FormatDirEntry</span> <span title="Added in Go 1.21">1.21</span> </h2> <pre data-language="go">func FormatDirEntry(dir DirEntry) string</pre> <p>FormatDirEntry returns a formatted version of dir for human readability. Implementations of <a href="#DirEntry">DirEntry</a> can call this from a String method. The outputs for a directory named subdir and a file named hello.go are: </p>
+<pre data-language="go">d subdir/
+- hello.go
+</pre> <h2 id="FormatFileInfo">func <span>FormatFileInfo</span> <span title="Added in Go 1.21">1.21</span> </h2> <pre data-language="go">func FormatFileInfo(info FileInfo) string</pre> <p>FormatFileInfo returns a formatted version of info for human readability. Implementations of <a href="#FileInfo">FileInfo</a> can call this from a String method. The output for a file named "hello.go", 100 bytes, mode 0o644, created January 1, 1970 at noon is </p>
+<pre data-language="go">-rw-r--r-- 100 1970-01-01 12:00:00 hello.go
+</pre> <h2 id="Glob">func <span>Glob</span> <span title="Added in Go 1.16">1.16</span> </h2> <pre data-language="go">func Glob(fsys FS, pattern string) (matches []string, err error)</pre> <p>Glob returns the names of all files matching pattern or nil if there is no matching file. The syntax of patterns is the same as in <span>path.Match</span>. The pattern may describe hierarchical names such as usr/*/bin/ed. </p>
+<p>Glob ignores file system errors such as I/O errors reading directories. The only possible returned error is <span>path.ErrBadPattern</span>, reporting that the pattern is malformed. </p>
+<p>If fs implements <a href="#GlobFS">GlobFS</a>, Glob calls fs.Glob. Otherwise, Glob uses <a href="#ReadDir">ReadDir</a> to traverse the directory tree and look for matches for the pattern. </p>
+<h2 id="ReadFile">func <span>ReadFile</span> <span title="Added in Go 1.16">1.16</span> </h2> <pre data-language="go">func ReadFile(fsys FS, name string) ([]byte, error)</pre> <p>ReadFile reads the named file from the file system fs and returns its contents. A successful call returns a nil error, not <span>io.EOF</span>. (Because ReadFile reads the whole file, the expected EOF from the final Read is not treated as an error to be reported.) </p>
+<p>If fs implements <a href="#ReadFileFS">ReadFileFS</a>, ReadFile calls fs.ReadFile. Otherwise ReadFile calls fs.Open and uses Read and Close on the returned <a href="#File">File</a>. </p>
+<h2 id="ValidPath">func <span>ValidPath</span> <span title="Added in Go 1.16">1.16</span> </h2> <pre data-language="go">func ValidPath(name string) bool</pre> <p>ValidPath reports whether the given path name is valid for use in a call to Open. </p>
+<p>Path names passed to open are UTF-8-encoded, unrooted, slash-separated sequences of path elements, like “x/y/z”. Path names must not contain an element that is “.” or “..” or the empty string, except for the special case that the root directory is named “.”. Paths must not start or end with a slash: “/x” and “x/” are invalid. </p>
+<p>Note that paths are slash-separated on all systems, even Windows. Paths containing other characters such as backslash and colon are accepted as valid, but those characters must never be interpreted by an <a href="#FS">FS</a> implementation as path element separators. </p>
+<h2 id="WalkDir">func <span>WalkDir</span> <span title="Added in Go 1.16">1.16</span> </h2> <pre data-language="go">func WalkDir(fsys FS, root string, fn WalkDirFunc) error</pre> <p>WalkDir walks the file tree rooted at root, calling fn for each file or directory in the tree, including root. </p>
+<p>All errors that arise visiting files and directories are filtered by fn: see the <a href="#WalkDirFunc">fs.WalkDirFunc</a> documentation for details. </p>
+<p>The files are walked in lexical order, which makes the output deterministic but requires WalkDir to read an entire directory into memory before proceeding to walk that directory. </p>
+<p>WalkDir does not follow symbolic links found in directories, but if root itself is a symbolic link, its target will be walked. </p> <h4 id="example_WalkDir"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">
+root := "/usr/local/go/bin"
+fileSystem := os.DirFS(root)
+
+fs.WalkDir(fileSystem, ".", func(path string, d fs.DirEntry, err error) error {
+ if err != nil {
+ log.Fatal(err)
+ }
+ fmt.Println(path)
+ return nil
+})
+</pre> <h2 id="DirEntry">type <span>DirEntry</span> <span title="Added in Go 1.16">1.16</span> </h2> <p>A DirEntry is an entry read from a directory (using the <a href="#ReadDir">ReadDir</a> function or a <a href="#ReadDirFile">ReadDirFile</a>'s ReadDir method). </p>
+<pre data-language="go">type DirEntry interface {
+ // Name returns the name of the file (or subdirectory) described by the entry.
+ // This name is only the final element of the path (the base name), not the entire path.
+ // For example, Name would return "hello.go" not "home/gopher/hello.go".
+ Name() string
+
+ // IsDir reports whether the entry describes a directory.
+ IsDir() bool
+
+ // Type returns the type bits for the entry.
+ // The type bits are a subset of the usual FileMode bits, those returned by the FileMode.Type method.
+ Type() FileMode
+
+ // Info returns the FileInfo for the file or subdirectory described by the entry.
+ // The returned FileInfo may be from the time of the original directory read
+ // or from the time of the call to Info. If the file has been removed or renamed
+ // since the directory read, Info may return an error satisfying errors.Is(err, ErrNotExist).
+ // If the entry denotes a symbolic link, Info reports the information about the link itself,
+ // not the link's target.
+ Info() (FileInfo, error)
+}</pre> <h3 id="FileInfoToDirEntry">func <span>FileInfoToDirEntry</span> <span title="Added in Go 1.17">1.17</span> </h3> <pre data-language="go">func FileInfoToDirEntry(info FileInfo) DirEntry</pre> <p>FileInfoToDirEntry returns a <a href="#DirEntry">DirEntry</a> that returns information from info. If info is nil, FileInfoToDirEntry returns nil. </p>
+<h3 id="ReadDir">func <span>ReadDir</span> <span title="Added in Go 1.16">1.16</span> </h3> <pre data-language="go">func ReadDir(fsys FS, name string) ([]DirEntry, error)</pre> <p>ReadDir reads the named directory and returns a list of directory entries sorted by filename. </p>
+<p>If fs implements <a href="#ReadDirFS">ReadDirFS</a>, ReadDir calls fs.ReadDir. Otherwise ReadDir calls fs.Open and uses ReadDir and Close on the returned file. </p>
+<h2 id="FS">type <span>FS</span> <span title="Added in Go 1.16">1.16</span> </h2> <p>An FS provides access to a hierarchical file system. </p>
+<p>The FS interface is the minimum implementation required of the file system. A file system may implement additional interfaces, such as <a href="#ReadFileFS">ReadFileFS</a>, to provide additional or optimized functionality. </p>
+<p><span>testing/fstest.TestFS</span> may be used to test implementations of an FS for correctness. </p>
+<pre data-language="go">type FS interface {
+ // Open opens the named file.
+ //
+ // When Open returns an error, it should be of type *PathError
+ // with the Op field set to "open", the Path field set to name,
+ // and the Err field describing the problem.
+ //
+ // Open should reject attempts to open names that do not satisfy
+ // ValidPath(name), returning a *PathError with Err set to
+ // ErrInvalid or ErrNotExist.
+ Open(name string) (File, error)
+}</pre> <h3 id="Sub">func <span>Sub</span> <span title="Added in Go 1.16">1.16</span> </h3> <pre data-language="go">func Sub(fsys FS, dir string) (FS, error)</pre> <p>Sub returns an <a href="#FS">FS</a> corresponding to the subtree rooted at fsys's dir. </p>
+<p>If dir is ".", Sub returns fsys unchanged. Otherwise, if fs implements <a href="#SubFS">SubFS</a>, Sub returns fsys.Sub(dir). Otherwise, Sub returns a new <a href="#FS">FS</a> implementation sub that, in effect, implements sub.Open(name) as fsys.Open(path.Join(dir, name)). The implementation also translates calls to ReadDir, ReadFile, and Glob appropriately. </p>
+<p>Note that Sub(os.DirFS("/"), "prefix") is equivalent to os.DirFS("/prefix") and that neither of them guarantees to avoid operating system accesses outside "/prefix", because the implementation of <span>os.DirFS</span> does not check for symbolic links inside "/prefix" that point to other directories. That is, <span>os.DirFS</span> is not a general substitute for a chroot-style security mechanism, and Sub does not change that fact. </p>
+<h2 id="File">type <span>File</span> <span title="Added in Go 1.16">1.16</span> </h2> <p>A File provides access to a single file. The File interface is the minimum implementation required of the file. Directory files should also implement <a href="#ReadDirFile">ReadDirFile</a>. A file may implement <span>io.ReaderAt</span> or <span>io.Seeker</span> as optimizations. </p>
+<pre data-language="go">type File interface {
+ Stat() (FileInfo, error)
+ Read([]byte) (int, error)
+ Close() error
+}</pre> <h2 id="FileInfo">type <span>FileInfo</span> <span title="Added in Go 1.16">1.16</span> </h2> <p>A FileInfo describes a file and is returned by <a href="#Stat">Stat</a>. </p>
+<pre data-language="go">type FileInfo interface {
+ Name() string // base name of the file
+ Size() int64 // length in bytes for regular files; system-dependent for others
+ Mode() FileMode // file mode bits
+ ModTime() time.Time // modification time
+ IsDir() bool // abbreviation for Mode().IsDir()
+ Sys() any // underlying data source (can return nil)
+}</pre> <h3 id="Stat">func <span>Stat</span> <span title="Added in Go 1.16">1.16</span> </h3> <pre data-language="go">func Stat(fsys FS, name string) (FileInfo, error)</pre> <p>Stat returns a <a href="#FileInfo">FileInfo</a> describing the named file from the file system. </p>
+<p>If fs implements <a href="#StatFS">StatFS</a>, Stat calls fs.Stat. Otherwise, Stat opens the <a href="#File">File</a> to stat it. </p>
+<h2 id="FileMode">type <span>FileMode</span> <span title="Added in Go 1.16">1.16</span> </h2> <p>A FileMode represents a file's mode and permission bits. The bits have the same definition on all systems, so that information about files can be moved from one system to another portably. Not all bits apply to all systems. The only required bit is <a href="#ModeDir">ModeDir</a> for directories. </p>
+<pre data-language="go">type FileMode uint32</pre> <p>The defined file mode bits are the most significant bits of the <a href="#FileMode">FileMode</a>. The nine least-significant bits are the standard Unix rwxrwxrwx permissions. The values of these bits should be considered part of the public API and may be used in wire protocols or disk representations: they must not be changed, although new bits might be added. </p>
+<pre data-language="go">const (
+ // The single letters are the abbreviations
+ // used by the String method's formatting.
+ ModeDir FileMode = 1 &lt;&lt; (32 - 1 - iota) // d: is a directory
+ ModeAppend // a: append-only
+ ModeExclusive // l: exclusive use
+ ModeTemporary // T: temporary file; Plan 9 only
+ ModeSymlink // L: symbolic link
+ ModeDevice // D: device file
+ ModeNamedPipe // p: named pipe (FIFO)
+ ModeSocket // S: Unix domain socket
+ ModeSetuid // u: setuid
+ ModeSetgid // g: setgid
+ ModeCharDevice // c: Unix character device, when ModeDevice is set
+ ModeSticky // t: sticky
+ ModeIrregular // ?: non-regular file; nothing else is known about this file
+
+ // Mask for the type bits. For regular files, none will be set.
+ ModeType = ModeDir | ModeSymlink | ModeNamedPipe | ModeSocket | ModeDevice | ModeCharDevice | ModeIrregular
+
+ ModePerm FileMode = 0777 // Unix permission bits
+)</pre> <h3 id="FileMode.IsDir">func (FileMode) <span>IsDir</span> <span title="Added in Go 1.16">1.16</span> </h3> <pre data-language="go">func (m FileMode) IsDir() bool</pre> <p>IsDir reports whether m describes a directory. That is, it tests for the <a href="#ModeDir">ModeDir</a> bit being set in m. </p>
+<h3 id="FileMode.IsRegular">func (FileMode) <span>IsRegular</span> <span title="Added in Go 1.16">1.16</span> </h3> <pre data-language="go">func (m FileMode) IsRegular() bool</pre> <p>IsRegular reports whether m describes a regular file. That is, it tests that no mode type bits are set. </p>
+<h3 id="FileMode.Perm">func (FileMode) <span>Perm</span> <span title="Added in Go 1.16">1.16</span> </h3> <pre data-language="go">func (m FileMode) Perm() FileMode</pre> <p>Perm returns the Unix permission bits in m (m &amp; <a href="#ModePerm">ModePerm</a>). </p>
+<h3 id="FileMode.String">func (FileMode) <span>String</span> <span title="Added in Go 1.16">1.16</span> </h3> <pre data-language="go">func (m FileMode) String() string</pre> <h3 id="FileMode.Type">func (FileMode) <span>Type</span> <span title="Added in Go 1.16">1.16</span> </h3> <pre data-language="go">func (m FileMode) Type() FileMode</pre> <p>Type returns type bits in m (m &amp; <a href="#ModeType">ModeType</a>). </p>
+<h2 id="GlobFS">type <span>GlobFS</span> <span title="Added in Go 1.16">1.16</span> </h2> <p>A GlobFS is a file system with a Glob method. </p>
+<pre data-language="go">type GlobFS interface {
+ FS
+
+ // Glob returns the names of all files matching pattern,
+ // providing an implementation of the top-level
+ // Glob function.
+ Glob(pattern string) ([]string, error)
+}</pre> <h2 id="PathError">type <span>PathError</span> <span title="Added in Go 1.16">1.16</span> </h2> <p>PathError records an error and the operation and file path that caused it. </p>
+<pre data-language="go">type PathError struct {
+ Op string
+ Path string
+ Err error
+}
+</pre> <h3 id="PathError.Error">func (*PathError) <span>Error</span> <span title="Added in Go 1.16">1.16</span> </h3> <pre data-language="go">func (e *PathError) Error() string</pre> <h3 id="PathError.Timeout">func (*PathError) <span>Timeout</span> <span title="Added in Go 1.16">1.16</span> </h3> <pre data-language="go">func (e *PathError) Timeout() bool</pre> <p>Timeout reports whether this error represents a timeout. </p>
+<h3 id="PathError.Unwrap">func (*PathError) <span>Unwrap</span> <span title="Added in Go 1.16">1.16</span> </h3> <pre data-language="go">func (e *PathError) Unwrap() error</pre> <h2 id="ReadDirFS">type <span>ReadDirFS</span> <span title="Added in Go 1.16">1.16</span> </h2> <p>ReadDirFS is the interface implemented by a file system that provides an optimized implementation of <a href="#ReadDir">ReadDir</a>. </p>
+<pre data-language="go">type ReadDirFS interface {
+ FS
+
+ // ReadDir reads the named directory
+ // and returns a list of directory entries sorted by filename.
+ ReadDir(name string) ([]DirEntry, error)
+}</pre> <h2 id="ReadDirFile">type <span>ReadDirFile</span> <span title="Added in Go 1.16">1.16</span> </h2> <p>A ReadDirFile is a directory file whose entries can be read with the ReadDir method. Every directory file should implement this interface. (It is permissible for any file to implement this interface, but if so ReadDir should return an error for non-directories.) </p>
+<pre data-language="go">type ReadDirFile interface {
+ File
+
+ // ReadDir reads the contents of the directory and returns
+ // a slice of up to n DirEntry values in directory order.
+ // Subsequent calls on the same file will yield further DirEntry values.
+ //
+ // If n &gt; 0, ReadDir returns at most n DirEntry structures.
+ // In this case, if ReadDir returns an empty slice, it will return
+ // a non-nil error explaining why.
+ // At the end of a directory, the error is io.EOF.
+ // (ReadDir must return io.EOF itself, not an error wrapping io.EOF.)
+ //
+ // If n &lt;= 0, ReadDir returns all the DirEntry values from the directory
+ // in a single slice. In this case, if ReadDir succeeds (reads all the way
+ // to the end of the directory), it returns the slice and a nil error.
+ // If it encounters an error before the end of the directory,
+ // ReadDir returns the DirEntry list read until that point and a non-nil error.
+ ReadDir(n int) ([]DirEntry, error)
+}</pre> <h2 id="ReadFileFS">type <span>ReadFileFS</span> <span title="Added in Go 1.16">1.16</span> </h2> <p>ReadFileFS is the interface implemented by a file system that provides an optimized implementation of <a href="#ReadFile">ReadFile</a>. </p>
+<pre data-language="go">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)
+}</pre> <h2 id="StatFS">type <span>StatFS</span> <span title="Added in Go 1.16">1.16</span> </h2> <p>A StatFS is a file system with a Stat method. </p>
+<pre data-language="go">type StatFS interface {
+ FS
+
+ // Stat returns a FileInfo describing the file.
+ // If there is an error, it should be of type *PathError.
+ Stat(name string) (FileInfo, error)
+}</pre> <h2 id="SubFS">type <span>SubFS</span> <span title="Added in Go 1.16">1.16</span> </h2> <p>A SubFS is a file system with a Sub method. </p>
+<pre data-language="go">type SubFS interface {
+ FS
+
+ // Sub returns an FS corresponding to the subtree rooted at dir.
+ Sub(dir string) (FS, error)
+}</pre> <h2 id="WalkDirFunc">type <span>WalkDirFunc</span> <span title="Added in Go 1.16">1.16</span> </h2> <p>WalkDirFunc is the type of the function called by <a href="#WalkDir">WalkDir</a> to visit each file or directory. </p>
+<p>The path argument contains the argument to <a href="#WalkDir">WalkDir</a> as a prefix. That is, if WalkDir is called with root argument "dir" and finds a file named "a" in that directory, the walk function will be called with argument "dir/a". </p>
+<p>The d argument is the <a href="#DirEntry">DirEntry</a> for the named path. </p>
+<p>The error result returned by the function controls how <a href="#WalkDir">WalkDir</a> continues. If the function returns the special value <a href="#SkipDir">SkipDir</a>, WalkDir skips the current directory (path if d.IsDir() is true, otherwise path's parent directory). If the function returns the special value <a href="#SkipAll">SkipAll</a>, WalkDir skips all remaining files and directories. Otherwise, if the function returns a non-nil error, WalkDir stops entirely and returns that error. </p>
+<p>The err argument reports an error related to path, signaling that <a href="#WalkDir">WalkDir</a> will not walk into that directory. The function can decide how to handle that error; as described earlier, returning the error will cause WalkDir to stop walking the entire tree. </p>
+<p><a href="#WalkDir">WalkDir</a> calls the function with a non-nil err argument in two cases. </p>
+<p>First, if the initial <a href="#Stat">Stat</a> on the root directory fails, WalkDir calls the function with path set to root, d set to nil, and err set to the error from <a href="#Stat">fs.Stat</a>. </p>
+<p>Second, if a directory's ReadDir method (see <a href="#ReadDirFile">ReadDirFile</a>) fails, WalkDir calls the function with path set to the directory's path, d set to an <a href="#DirEntry">DirEntry</a> describing the directory, and err set to the error from ReadDir. In this second case, the function is called twice with the path of the directory: the first call is before the directory read is attempted and has err set to nil, giving the function a chance to return <a href="#SkipDir">SkipDir</a> or <a href="#SkipAll">SkipAll</a> and avoid the ReadDir entirely. The second call is after a failed ReadDir and reports the error from ReadDir. (If ReadDir succeeds, there is no second call.) </p>
+<p>The differences between WalkDirFunc compared to <span>path/filepath.WalkFunc</span> are: </p>
+<ul> <li>The second argument has type <a href="#DirEntry">DirEntry</a> instead of <a href="#FileInfo">FileInfo</a>. </li>
+<li>The function is called before reading a directory, to allow <a href="#SkipDir">SkipDir</a> or <a href="#SkipAll">SkipAll</a> to bypass the directory read entirely or skip all remaining files and directories respectively. </li>
+<li>If a directory read fails, the function is called a second time for that directory to report the error. </li>
+</ul> <pre data-language="go">type WalkDirFunc func(path string, d DirEntry, err error) error</pre><div class="_attribution">
+ <p class="_attribution-p">
+ &copy; Google, Inc.<br>Licensed under the Creative Commons Attribution License 3.0.<br>
+ <a href="http://golang.org/pkg/io/fs/" class="_attribution-link">http://golang.org/pkg/io/fs/</a>
+ </p>
+</div>