Beispiel #1
0
func writeBakedFSCode(w io.Writer, opts *bakeOptions, extensions []string) (err error) {
	if opts.VFS {
		if _, err = io.WriteString(w, "import \"gnd.la/util/vfsutil\"\n"); err != nil {
			return err
		}
	}
	var buf bytes.Buffer
	if err := vfsutil.Bake(&buf, opts.Dir, extensions); err != nil {
		return err
	}
	data := buf.String()
	var files []string
	fs, err := vfs.TarGzip(bytes.NewReader(buf.Bytes()))
	if err != nil {
		return err
	}
	err = vfs.Walk(fs, "/", func(fs vfs.VFS, path string, info os.FileInfo, err error) error {
		if !info.IsDir() {
			files = append(files, strings.TrimPrefix(path, "/"))
		}
		return err
	})
	if err != nil {
		return err
	}
	if len(files) > 0 {
		if _, err := fmt.Fprintf(w, "// %s \n", strings.Join(files, ", ")); err != nil {
			return err
		}
	}
	if _, err := fmt.Fprintf(w, "var %s = ", opts.Name); err != nil {
		return err
	}
	if opts.VFS {
		_, err = fmt.Fprintf(w, "vfsutil.MustOpenBaked(%q)\n", data)
	} else {
		_, err = fmt.Fprintf(w, "%q\n", data)
	}
	return err
}
Beispiel #2
0
// OpenBaked opens a VFS baked into a string using gondola bake
func OpenBaked(s string) (VFS, error) {
	return vfs.TarGzip(strings.NewReader(s))
}