Documentation ¶
Overview ¶
Package zipfs provides an implementation of the net/http.FileSystem interface based on the contents of a ZIP file. It also provides the FileServer function, which returns a net/http.Handler that serves static files from a ZIP file. This HTTP handler exploits the fact that most files are stored in a ZIP file using the deflate compression algorithm, and that most HTTP user agents will accept deflate as a content-encoding. When possible the HTTP handler will send the compressed file contents back to the user agent without having to decompress the ZIP file contents.
Example ¶
package main import ( "net/http" "github.com/FlashpointProject/zipfs" ) func main() error { fs, err := zipfs.New("testdata/testdata.zip") if err != nil { return err } extensions := []string{"html", "htm"} return http.ListenAndServe(":8080", zipfs.FileServer(fs, "test/base/api/", "", true, extensions, nil)) }
Output:
Index ¶
- func Cgi(w http.ResponseWriter, r *http.Request, phpBin string, scriptFileName string)
- func EmptyFileServer(baseAPIPath string, urlPrepend string, isVerbose bool, indexExts []string, ...) http.Handler
- func FileServer(fs *FileSystem, baseAPIPath string, urlPrepend string, isVerbose bool, ...) http.Handler
- func FileServers(fs []*FileSystem, baseAPIPath string, urlPrepend string, isVerbose bool, ...) http.Handler
- type FileSystem
- type Mount
- type MountList
- type SimpleResponseData
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EmptyFileServer ¶
func FileServer ¶
func FileServer(fs *FileSystem, baseAPIPath string, urlPrepend string, isVerbose bool, indexExts []string, mimeExts map[string]string) http.Handler
FileServer returns a HTTP handler that serves HTTP requests with the contents of the ZIP file system. It provides slightly better performance than the http.FileServer implementation because it serves compressed content to clients that can accept the "deflate" compression algorithm.
Types ¶
type FileSystem ¶
type FileSystem struct {
// contains filtered or unexported fields
}
FileSystem is a file system based on a ZIP file. It implements the http.FileSystem interface.
func New ¶
func New(name string) (*FileSystem, error)
New will open the Zip file specified by name and return a new FileSystem based on that Zip file.
func NewFromReaderAt ¶
func NewFromReaderAt(readerAt io.ReaderAt, size int64, closer io.Closer, filePath string) (*FileSystem, error)
NewFromReaderAt will open the Zip file accessible by readerAt with the given size. The closer, if not nil, will be called when the file system is closed.
func (*FileSystem) Close ¶
func (fs *FileSystem) Close() error
Close closes the file system's underlying ZIP file and releases all memory allocated to internal data structures.
type SimpleResponseData ¶
type SimpleResponseData struct {
Message string `json:"msg"`
}