bundle

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2022 License: MIT Imports: 10 Imported by: 0

README

Go Asset Bundle

Go Report Card License

Just like asar 😂

Usage

go get -u github.com/gizmo-ds/go-asset-bundle

Or install the CLI tools

go install github.com/gizmo-ds/go-asset-bundle/cmd/goab-cli@latest

Example

example

Create an AssetBundle
ab, _ := bundle.NewAssetBundle("./public.ab")
defer ab.Close()

var version uint16 = 1000
ab.Bundle("./public", version)

Or use the CLI tool

goab-cli pack -o="./public.ab" -v=1000 ./public
Use an AssetBundle
ab, _ := bundle.OpenAssetBundle("./public.ab")
defer ab.Close()

fmt.Println("Version", ab.Version)

http.Handle("/", http.StripPrefix("/", http.FileServer(ab)))
addr := fmt.Sprintf("127.0.0.1:%d", 3000)
fmt.Println("http server started on", addr)
http.ListenAndServe(addr, nil)

Thanks

Thanks to JetBrains for the open source license(s).

JetBrains Logo

License

Code is distributed under MIT license, feel free to use it in your proprietary projects as well.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FI = []byte("GoAB")

FI 文件头部标识

Functions

This section is empty.

Types

type ABFileInfo

type ABFileInfo struct {
	Path    string `json:"p"`
	ModTime int64  `json:"t"`
	Size    int64  `json:"s"`
	At      int64  `json:"a"`
}

ABFileInfo 资源包文件信息

type AssetBundle

type AssetBundle struct {
	Size    int64
	Head    []byte
	Files   []ABFileInfo
	Version uint16
	// contains filtered or unexported fields
}

AssetBundle 资源包

func NewAssetBundle

func NewAssetBundle(name string) (*AssetBundle, error)

NewAssetBundle 创建一个新的资源包

func OpenAssetBundle

func OpenAssetBundle(name string) (*AssetBundle, error)

OpenAssetBundle 从文件打开资源包

func (*AssetBundle) Bundle

func (ab *AssetBundle) Bundle(root string, version uint16) error

Bundle 捆绑指定目录的资源

func (*AssetBundle) Close

func (ab *AssetBundle) Close() error

Close 关闭资源包

func (*AssetBundle) Open

func (ab *AssetBundle) Open(name string) (http.File, error)

Open 实现http.FileSystem

type File

type File struct {
	*bytes.Reader
	// contains filtered or unexported fields
}

File 实现http.File

func (*File) Close

func (f *File) Close() error

Close 永远都不会关闭的

func (*File) Read

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

Read 实现接口

func (*File) Readdir

func (f *File) Readdir(_ int) ([]os.FileInfo, error)

Readdir 实现接口

func (*File) Stat

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

Stat 实现接口

type FileInfo

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

FileInfo 实现os.FileInfo

func (*FileInfo) IsDir

func (f *FileInfo) IsDir() bool

IsDir 实现接口

func (*FileInfo) ModTime

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

ModTime 实现接口

func (*FileInfo) Mode

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

Mode 实现接口

func (*FileInfo) Name

func (f *FileInfo) Name() string

Name 实现接口

func (*FileInfo) Size

func (f *FileInfo) Size() int64

Size 实现接口

func (*FileInfo) Sys

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

Sys 实现接口

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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