zipfs

package module
v0.0.0-...-5f563d2 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2023 License: BSD-3-Clause Imports: 25 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.

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

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cgi

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

func EmptyFileServer

func EmptyFileServer(baseAPIPath string, urlPrepend string, isVerbose bool, indexExts []string, baseMountDir string, phpPath string, mimeExts map[string]string, overrideBases []string, htdocsPath string) 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 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.

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 Mount

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

type MountList

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

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