// readFile reads an arbitrary file into a buffer. func readFile(filename string, buf *bytes.Buffer) (int64, error) { f, err := fs.Open(filename) if err != nil { return -1, err } defer f.Close() return buf.ReadFrom(f) }
func (p dir) Open(path string) (io.ReadWriteCloser, error) { if path == "/" { return nil, fmt.Errorf("I'm a directory!") } head, tail := split(path) fs, ok := p.entries[head] if !ok { return nil, fmt.Errorf("Not found: %s", path) } return fs.Open(tail) }