zipfs

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2018 License: MIT Imports: 11 Imported by: 2

README

GoDoc

ZipFS for net/http

Installation

$ go get github.com/cjtoolkit/zipfs

Example

package main

import (
	"fmt"
	"log"
	"net/http"

	"github.com/cjtoolkit/zipfs"
)

func main() {
	// Init ZipFS, if the zip file does not exist it will fallback to embedded zip file within application, if that
	// also does not exist, it will panic.
	fs := zipfs.InitZipFs("asset.zip")

	fmt.Println("Running ZipFS via http server on port 8080.")
	log.Print(http.ListenAndServe(":8080", http.FileServer(fs)))
}

To embed zip to the application, first create a zip file with your preferred achiever with compression disabled. Than append the content of the zip file to the compiled application. You can use this simple shell command to append.

$ cat asset.zip >> application

Credit

This project is based on the work of the following:

Documentation

Overview

Package that host the content of a zip via Google net/http.

Example:

package main

import (
	"fmt"
	"log"
	"net/http"

	"github.com/cjtoolkit/zipfs"
)

func main() {
	// Init ZipFS, if the zip file does not exist it will fallback to embedded zip file within application, if that
	// also does not exist, it will panic.
	fs := zipfs.InitZipFs("asset.zip")

	fmt.Println("Running ZipFS via http server on port 8080.")
	log.Print(http.ListenAndServe(":8080", http.FileServer(fs)))
}

To embed zip to the application, first create a zip file with your preferred achiever with compression disabled. Than append the content of the zip to the compiled application. You can use this simple shell command to append.

$ cat asset.zip >> application

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetEmbeddedZip

func GetEmbeddedZip() (*zip.Reader, io.ReaderAt, error)

Tries to get the zip archive, that is embedded inside the running application.

func InitZipFs

func InitZipFs(zipFileName string) http.FileSystem

Initialise ZipFS based on given zip file name. If the file does not exist, it will try to get the zip file that is embedded in the application itself. If the application also does not have zip embedded it will panic.

func InitZipFsFromHttpFile

func InitZipFsFromHttpFile(f http.File) http.FileSystem

Init Zip FS from HTTP File, must be uncompressed. Does not support compressed files!

func Must

func Must(f http.File, err error) http.File

Must not have any error, in HTTP File.

func NewZipFS

func NewZipFS(z *zip.Reader) http.FileSystem

Create Zip File System, just from the zip reader, with seek disabled.

func NewZipFSWithReaderAt

func NewZipFSWithReaderAt(z *zip.Reader, readerAt io.ReaderAt) http.FileSystem

Create Zip File System, from the zip reader and readerAt. If readerAt is nil, than seeking will be disabled.

func Prefix

func Prefix(prefix string, fileSystem http.FileSystem) http.FileSystem

Add prefix to name

Types

This section is empty.

Jump to

Keyboard shortcuts

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