Skip to content

Latest commit

 

History

History

zipfs

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

zipfs

Go lang zip http.FileSystem

Installation

$ go get github.com/gnue/httpfs/zipfs

Usage

import "github.com/gnue/httpfs/zipfs"

Examples

New

package main

import (
	"github.com/gnue/httpfs/zipfs"
	"log"
	"net/http"
	"os"
)

func main() {
	b, err := os.ReadFile("public.zip")
	if err != nil {
		log.Fatal(err)
	}

	fs, err := zipfs.New(b, &zipfs.Options{Prefix: "public"})
	if err != nil {
		log.Fatal(err)
	}

	http.Handle("/", http.FileServer(fs))
	http.ListenAndServe(":8080", nil)
}

Simple zip webserver(use New)

Open

package main

import (
	"github.com/gnue/httpfs/zipfs"
	"log"
	"net/http"
)

func main() {
	fs, err := zipfs.Open("public.zip", &zipfs.Options{Prefix: "public"})
	if err != nil {
		log.Fatal(err)
	}
	defer fs.Close()

	http.Handle("/", http.FileServer(fs))
	http.ListenAndServe(":8080", nil)
}

Simple zip webserver(use Open)

Author

gnue

License

MIT