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/jyd519/zipfs" ) func main() error { fs, err := zipfs.New("testdata/testdata.zip") if err != nil { return err } h := zipfs.FileServer(fs) return http.ListenAndServe(":8080", h) }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FileHandler ¶
type FileHandler struct { CacheDir string // contains filtered or unexported fields }
func FileServer ¶
func FileServer(fs *FileSystem) *FileHandler
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.
func (*FileHandler) Close ¶
func (h *FileHandler) Close() error
func (*FileHandler) ServeHTTP ¶
func (h *FileHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
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 WithPassword ¶
func WithPassword(name, password string) (*FileSystem, error)
WithPassword will open the encrypted Zip file specified by name and return a new FileSystem based on that Zip file.
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.