// 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 (
	
	
)

// ReadDirFS is the interface implemented by a file system
// that provides an optimized implementation of ReadDir.
type ReadDirFS interface {
	FS

	// ReadDir reads the named directory
	// and returns a list of directory entries sorted by filename.
	ReadDir(name string) ([]DirEntry, error)
}

// ReadDir reads the named directory
// and returns a list of directory entries sorted by filename.
//
// If fs implements ReadDirFS, ReadDir calls fs.ReadDir.
// Otherwise ReadDir calls fs.Open and uses ReadDir and Close
// on the returned file.
func ( FS,  string) ([]DirEntry, error) {
	if ,  := .(ReadDirFS);  {
		return .ReadDir()
	}

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

	,  := .(ReadDirFile)
	if ! {
		return nil, &PathError{Op: "readdir", Path: , Err: errors.New("not implemented")}
	}

	,  := .ReadDir(-1)
	sort.Slice(, func(,  int) bool { return [].Name() < [].Name() })
	return , 
}