Skip to content

The Fileutil Package

Patrick Stephen edited this page Dec 4, 2021 · 4 revisions

Oak provides a fileutil package which allows for the embedding of binary data such as images and audio in an oak binary via any io/fs.FS implementation. A common implementation is that provided by the standard library's embed package.

Setting fileutil.FS will cause all directory or file reads oak performs to be performed on that FS.

fileutil offers a couple boolean configurable options:

// FixWindowsPaths will reset all file paths loaded to replace windows style slashes
// with unix style slashes. This is important when using io/fs or embed, because the
// path/filepath package will produce windows style paths on a windows system, but
// these stdlib packages will reject all windows paths.
FixWindowsPaths = true
// OSFallback will fallback to loading via os.Open / io.ReadFile if loading otherwise fails.
// This is necessary when reading system level fallback fonts. Fixed paths will not be applied
// to this fallback route.
OSFallback = true