i = len(st.Src)
}
filename := st.Src[0:i]
- data, err := fs.ReadFile(absolutePath(filename, *goroot))
+ data, err := ReadFile(fs, absolutePath(filename, *goroot))
if err != nil {
st.Err = err
continue
// the usual godoc HTML wrapper.
func codewalkFileprint(w http.ResponseWriter, r *http.Request, f string) {
abspath := absolutePath(f, *goroot)
- data, err := fs.ReadFile(abspath)
+ data, err := ReadFile(fs, abspath)
if err != nil {
log.Print(err)
serveError(w, r, f, err)
Lstat(path string) (FileInfo, os.Error)
Stat(path string) (FileInfo, os.Error)
ReadDir(path string) ([]FileInfo, os.Error)
- ReadFile(path string) ([]byte, os.Error)
+}
+
+// ReadFile reads the file named by path from fs and returns the contents.
+func ReadFile(fs FileSystem, path string) ([]byte, os.Error) {
+ rc, err := fs.Open(path)
+ if err != nil {
+ return nil, err
+ }
+ defer rc.Close()
+ return ioutil.ReadAll(rc)
}
// ----------------------------------------------------------------------------
}
return l1, nil
}
-
-func (osFS) ReadFile(path string) ([]byte, os.Error) {
- return ioutil.ReadFile(path)
-}
// readDirList reads a file containing a newline-separated list
// of directory paths and returns the list of paths.
func readDirList(filename string) ([]string, os.Error) {
- contents, err := fs.ReadFile(filename)
+ contents, err := ReadFile(fs, filename)
if err != nil {
return nil, err
}
// use underlying file system fs to read the template file
// (cannot use template ParseFile functions directly)
- data, err := fs.ReadFile(path)
+ data, err := ReadFile(fs, path)
if err != nil {
log.Fatal("readTemplate: ", err)
}
func serveHTMLDoc(w http.ResponseWriter, r *http.Request, abspath, relpath string) {
// get HTML body contents
- src, err := fs.ReadFile(abspath)
+ src, err := ReadFile(fs, abspath)
if err != nil {
log.Printf("ReadFile: %s", err)
serveError(w, r, relpath, err)
}
func serveTextFile(w http.ResponseWriter, r *http.Request, abspath, relpath, title string) {
- src, err := fs.ReadFile(abspath)
+ src, err := ReadFile(fs, abspath)
if err != nil {
log.Printf("ReadFile: %s", err)
serveError(w, r, relpath, err)
// fsReadFile implements ReadFile for the go/build package.
func fsReadFile(dir, name string) (path string, data []byte, err os.Error) {
path = filepath.Join(dir, name)
- data, err = fs.ReadFile(path)
+ data, err = ReadFile(fs, path)
return
}
"archive/zip"
"fmt"
"io"
- "io/ioutil"
"os"
"path"
"sort"
return list, nil
}
-func (fs *zipFS) ReadFile(abspath string) ([]byte, os.Error) {
- rc, err := fs.Open(abspath)
- if err != nil {
- return nil, err
- }
- return ioutil.ReadAll(rc)
-}
-
func NewZipFS(rc *zip.ReadCloser) FileSystem {
list := make(zipList, len(rc.File))
copy(list, rc.File) // sort a copy of rc.File