vfsutil.go

 1// Package vfsutil implements some I/O utility functions for http.FileSystem.
 2package vfsutil
 3
 4import (
 5	"io/ioutil"
 6	"net/http"
 7	"os"
 8)
 9
10// ReadDir reads the contents of the directory associated with file and
11// returns a slice of FileInfo values in directory order.
12func ReadDir(fs http.FileSystem, name string) ([]os.FileInfo, error) {
13	f, err := fs.Open(name)
14	if err != nil {
15		return nil, err
16	}
17	defer f.Close()
18	return f.Readdir(0)
19}
20
21// Stat returns the FileInfo structure describing file.
22func Stat(fs http.FileSystem, name string) (os.FileInfo, error) {
23	f, err := fs.Open(name)
24	if err != nil {
25		return nil, err
26	}
27	defer f.Close()
28	return f.Stat()
29}
30
31// ReadFile reads the file named by path from fs and returns the contents.
32func ReadFile(fs http.FileSystem, path string) ([]byte, error) {
33	rc, err := fs.Open(path)
34	if err != nil {
35		return nil, err
36	}
37	defer rc.Close()
38	return ioutil.ReadAll(rc)
39}