zipfs

package module
v0.0.0-...-c619332 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 20, 2025 License: BSD-3-Clause Imports: 29 Imported by: 0

README

ZIP-based File System for serving HTTP requests

GoDoc Build Status (Linux) Build status (Windows) Coverage Status GoReportCard License

Package zipfs provides a convenient way for a HTTP server to serve static content from a ZIP file.

Usage is simple. See the example in the GoDoc documentation.

License

Some of the code in this project is based on code in the net/http package in the Go standard library. For this reason, this package has the same license as the Go standard library.

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.

Index

Constants

View Source
const (
	CtxUsingHtaccess    contextKey = "using-htaccess"
	CtxPerformedRewrite contextKey = "performed-rewrite"
)

Variables

This section is empty.

Functions

func BuildHtaccessChain

func BuildHtaccessChain(htaccessHandlers map[string]*HtaccessHandler, requestPath string, finalHandler http.Handler) (http.Handler, bool)

func Cgi

func Cgi(w http.ResponseWriter, r *http.Request, phpBin string, scriptFileName string, htdocsPath string)

func EmptyFileServer

func EmptyFileServer(baseAPIPath string, urlPrepend string, isVerbose bool, indexExts []string, baseMountDir string, phpPath string, mimeExts map[string]string, extScriptTypes []string, overrideBases []string, htdocsPath string, enableHtaccess bool) http.Handler

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.

func FileServers

func FileServers(fs []*FileSystem, baseAPIPath string, urlPrepend string, isVerbose bool, indexExts []string, mimeExts map[string]string) http.Handler

Types

type ArchiveData

type ArchiveData struct {
	FilePath          string `json:"filePath"`
	CompressionMethod int16  `json:"compressionMethod"`
	Offset            int64  `json:"offset"`
	CompressedLength  int64  `json:"compressedLength"`
	Length            int64  `json:"length"`
}

type DirExistsFunc

type DirExistsFunc func(path string) (exists bool)

type FileExistsFunc

type FileExistsFunc func(path string) (exists bool)

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 NewArchiveData

func NewArchiveData(archiveData ArchiveData) (*FileSystem, error)

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.

func (*FileSystem) Open

func (fs *FileSystem) Open(name string) (http.File, error)

Open implements the http.FileSystem interface. A http.File is returned, which can be served by the http.FileServer implementation.

type HtaccessHandler

type HtaccessHandler struct {
	Rules       []RewriteRule
	RewriteBase string
	Next        http.Handler
	// contains filtered or unexported fields
}

HtaccessHandler wraps the parsed .htaccess rules

func CreateHtaccessHandler

func CreateHtaccessHandler(filepath string, next http.Handler, fileExists *FileExistsFunc, dirExists *DirExistsFunc) (*HtaccessHandler, error)

ParseHTAccess parses a .htaccess file and returns a handler

func (*HtaccessHandler) ServeHTTP

func (h *HtaccessHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler

type Mount

type Mount struct {
	FilePath    *string      `json:"filePath"`
	ArchiveData *ArchiveData `json:"archiveData"`
}

type MountList

type MountList struct {
	MountedZips []string `json:"mountedZips"`
}

type RewriteCond

type RewriteCond struct {
	TestString  string
	CondPattern string
	Pattern     *regexp.Regexp
	Flags       map[string]string
}

RewriteCond represents a RewriteCond directive

type RewriteRule

type RewriteRule struct {
	Pattern      *regexp.Regexp
	Substitution string
	Flags        map[string]string
	Conditions   []RewriteCond
}

RewriteRule represents a single Apache RewriteRule

type SimpleResponseData

type SimpleResponseData struct {
	Message string `json:"msg"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL