zipfs

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2024 License: MIT, MIT Imports: 9 Imported by: 0

README

zipfs

Go lang zip http.FileSystem

Installation

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

Usage

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

Examples

New
package main

import (
	"github.com/dolfly/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/dolfly/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

Documentation

Overview

Go lang zip http.FileSystem

Index

Examples

Constants

This section is empty.

Variables

View Source
var OSX_Ignore = []string{"__MACOSX", ".DS_Store"}

Functions

func NewIgnore

func NewIgnore(pattern []string) (*regexp.Regexp, error)

Types

type Dinfo

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

func (*Dinfo) FileInfo

func (d *Dinfo) FileInfo() os.FileInfo

func (*Dinfo) Open

func (d *Dinfo) Open() (http.File, error)

type Dir

type Dir struct {
	*Dinfo
	// contains filtered or unexported fields
}

func (*Dir) Close

func (d *Dir) Close() error

func (*Dir) Read

func (d *Dir) Read(p []byte) (int, error)

func (*Dir) Readdir

func (d *Dir) Readdir(count int) (finfos []os.FileInfo, err error)

func (*Dir) Seek

func (d *Dir) Seek(offset int64, whence int) (int64, error)

func (*Dir) Stat

func (d *Dir) Stat() (os.FileInfo, error)

type DirInfo

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

func (*DirInfo) IsDir

func (f *DirInfo) IsDir() bool

func (*DirInfo) ModTime

func (f *DirInfo) ModTime() time.Time

func (*DirInfo) Mode

func (f *DirInfo) Mode() os.FileMode

func (*DirInfo) Name

func (f *DirInfo) Name() string

func (*DirInfo) Size

func (f *DirInfo) Size() int64

func (*DirInfo) Sys

func (f *DirInfo) Sys() interface{}

type File

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

func (*File) Close

func (f *File) Close() error

func (*File) Read

func (f *File) Read(p []byte) (int, error)

func (*File) Readdir

func (f *File) Readdir(count int) (finfos []os.FileInfo, err error)

func (*File) Seek

func (f *File) Seek(offset int64, whence int) (int64, error)

func (*File) Stat

func (f *File) Stat() (os.FileInfo, error)

type FileSystem

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

func New

func New(data []byte, opts *Options) (*FileSystem, error)
Example

Simple zip webserver(use New)

package main

import (
	"log"
	"net/http"
	"os"

	"github.com/dolfly/httpfs/zipfs"
)

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)
}
Output:

func (*FileSystem) Open

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

type FileSystemCloser

type FileSystemCloser struct {
	FileSystem
	Filename string
	// contains filtered or unexported fields
}

func Open

func Open(name string, opts *Options) (*FileSystemCloser, error)
Example

Simple zip webserver(use Open)

package main

import (
	"log"
	"net/http"

	"github.com/dolfly/httpfs/zipfs"
)

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)
}
Output:

func (*FileSystemCloser) Close

func (z *FileSystemCloser) Close() error

type Finfo

type Finfo interface {
	FileInfo() os.FileInfo
	Open() (http.File, error)
}

type Options

type Options struct {
	Prefix string
	Ignore []string
}

type ReadCloser

type ReadCloser interface {
	Reader
	io.Closer
}

ReadCloser

type Reader

type Reader interface {
	File() []*zip.File
	Comment() string
	RegisterDecompressor(method uint16, dcomp zip.Decompressor)
}

Reader

type ZipFile

type ZipFile struct {
	File *zip.File
}

func (*ZipFile) FileInfo

func (z *ZipFile) FileInfo() os.FileInfo

func (*ZipFile) Open

func (z *ZipFile) Open() (http.File, error)

Jump to

Keyboard shortcuts

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