Help us shape the future of Go! Take the 2026 Go Developer Survey

staticfile

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2019 License: BSD-3-Clause Imports: 10 Imported by: 1

README

filedata

http://godoc.org/github.com/creachadair/staticfile

This repository provides a tool to compile static data into a Go binary, and to access those data via a file-like interface.

The compiledata program generates a Go source file in the specified package that embeds the contents of the named file globs:

compiledata -pkg staticdata -out static.go data/*

The resulting file can be compiled into a package in the usual way. This tool can also be invoked from go generate rules.

In common use, the main package will blank import the static data package, and other packages access the files via the staticfile package:

import "github.com/creachadair/staticfile"

f, err := staticfile.Open("data/main.css")
...
defer f.Close()
doStuffWith(f)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MustReadAll

func MustReadAll(path string) []byte

MustReadAll returns the full content of the specified static file or panics. It is intended for use during program initialization.

func ReadAll

func ReadAll(path string) ([]byte, error)

ReadAll reads the complete contents of a static file given its clean registered path. It reports io.ErrNotExist if no such path is registered.

func Register

func Register(path, data string)

Register the contents of a file under the given path. The path is cleaned by filepath.Clean, and any leading path separators are discarded. This function will panic if path == "" or if the cleaned path has previously been registered.

This function is meant to be used from generated code, and should not ordinarily be called directly by clients of the library.

Types

type File

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

A File is a read-only view of the contents of a static file. It implements io.Reader, io.ReaderAt, io.Seeker, and io.WriterTo.

func Open

func Open(path string) (*File, error)

Open opens a static file given its clean registered path. It reports io.ErrNotExist if no such path is registered.

func (*File) Close

func (*File) Close() error

Close implements io.Closer. This implementation never returns an error.

func (*File) Read

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

Read implements the io.Reader interface.

func (*File) ReadAt

func (f *File) ReadAt(data []byte, off int64) (int, error)

ReadAt implements the io.ReaderAt interface.

func (*File) Seek

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

Seek implements the io.Seeker interface.

func (*File) Size

func (f *File) Size() int64

Size reports the total unencoded size of the file contents, in bytes.

func (*File) WriteTo

func (f *File) WriteTo(w io.Writer) (int64, error)

WriteTo implements the io.WriterTo interface

Directories

Path Synopsis
Binary compiledata generates Go source text containing encoded file data, for use with the github.com/creachadair/staticfile package.
Binary compiledata generates Go source text containing encoded file data, for use with the github.com/creachadair/staticfile package.
internal
bits
Package bits provides support routines for encoding and decoding data.
Package bits provides support routines for encoding and decoding data.

Jump to

Keyboard shortcuts

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