Example #1
0
func (af *AssetFile) Read(p []byte) (n int, err error) {
	if af.data == nil {
		af.data, err = rtfblog_resources.Asset(af.name)
	}
	n64 := min(len64(p), len64(af.data)-af.seekIndex)
	copy(p, af.data[af.seekIndex:af.seekIndex+n64])
	return int(n64), err
}
Example #2
0
func (a *AssetBin) Open(name string) (http.File, error) {
	d := http.Dir(a.root)
	f, err := d.Open(name)
	if err == nil {
		return f, err
	}
	if name[0] == '/' {
		name = name[1:]
	}
	data, err := rtfblog_resources.Asset(name)
	return &AssetFile{
		name: name,
		data: data,
	}, err
}
Example #3
0
func (a *AssetBin) Load(path string) ([]byte, error) {
	fullPath := path
	if fullPath[0] != '/' {
		fullPath = filepath.Join(a.root, path)
	}
	exists, err := fileExists(fullPath)
	if err != nil {
		return nil, err
	}
	// Physical file takes precedence
	if exists {
		return ioutil.ReadFile(fullPath)
	}
	// Fall back to baked asset
	return rtfblog_resources.Asset(path)
}