...

Source file src/github.com/shurcooL/httpfs/vfsutil/vfsutil.go

Documentation: github.com/shurcooL/httpfs/vfsutil

     1  // Package vfsutil implements some I/O utility functions for http.FileSystem.
     2  package vfsutil
     3  
     4  import (
     5  	"io"
     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.
    12  func 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.
    22  func 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.
    32  func 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 io.ReadAll(rc)
    39  }
    40  

View as plain text