httpzip

package module
v0.0.0-...-4078dc8 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2016 License: MIT Imports: 10 Imported by: 0

README

httpzip

GoDoc Build Status Coverage Status

Package httzip allows you to connect a zip archive to the web server as static files handler.

package main

import (
	"log"
	"net/http"

	"github.com/mdigger/httpzip"
)

func main() {
	// open zip-file
	zipServer, err := httpzip.Open("static.zip")
	if err != nil {
		log.Fatal(err)
	}
	defer zipServer.Close()

	// initialize http handler
	http.Handle("/static/", http.StripPrefix("/static/", zipServer))
}

Documentation

Overview

Package httzip allows you to connect a zip archive to the web server as static files handler.

Example
package main

import (
	"log"
	"net/http"

	"github.com/mdigger/httpzip"
)

func main() {
	// open zip-file
	zipServer, err := httpzip.Open("static.zip")
	if err != nil {
		log.Fatal(err)
	}
	defer zipServer.Close()

	// initialize http handler
	http.Handle("/static/", http.StripPrefix("/static/", zipServer))
}
Output:

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrClosed = errors.New("httpzip: client closed")

Functions

This section is empty.

Types

type HTTPZip

type HTTPZip struct {
	// contains filtered or unexported fields
}

func New

func New(r *zip.Reader) *HTTPZip

func Open

func Open(filename string) (*HTTPZip, error)

func (*HTTPZip) Close

func (h *HTTPZip) Close() error

func (*HTTPZip) GetData

func (h *HTTPZip) GetData(name string) ([]byte, error)

GetData возвращает содержимое файла с указанным именем. Если такого файла в архиве нет, то возвращается ошибка.

func (*HTTPZip) GetMimeType

func (h *HTTPZip) GetMimeType() string

func (*HTTPZip) Open

func (h *HTTPZip) Open(name string) (*openedFile, error)

func (*HTTPZip) ServeFile

func (h *HTTPZip) ServeFile(w http.ResponseWriter, r *http.Request, name string)

func (*HTTPZip) ServeHTTP

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

ServeHTTP обеспечивает поддержку интерфейса http.Handler.

Directories

Path Synopsis
Простой упаковщик в ZIP-файл.
Простой упаковщик в ZIP-файл.

Jump to

Keyboard shortcuts

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