Why a `afero.File` can be converted into `hugolib. pathLangFileFi`

Apology for my poor golang knowledge.

i need some help to understand the code in hugo.

the following code are copied from hugolib/page_bundler_capture.go

import "github.com/spf13/afero"

func (c *capturer) readDir(dirname string) (pathLangFileFis, error) {
    if c.sourceSpec.IgnoreFile(dirname) {
        return nil, nil

    dir, err := c.fs.Open(dirname)
    // ...
    fis, err := dir.Readdir(-1)
    if err != nil {
        return nil, err

    pfis := make(pathLangFileFis, 0, len(fis))

    for _, fi := range fis {
        //// THE STRANGE PART ////
        fip := fi.(pathLangFileFi)

        /// ...

    return pfis, nil

I think a hugolib.pathLangFileFi could be converted to afero.File,
but, the oppsite conversion, I don’t follow.

thanks a lot.

Readdir returns a []os.FileInfo. os.FileInfo is an interface that is supported by pathLangFileFi(I should have picked a better name for that interface, but it is an internal interface). I need to revisit and clean up this, but you will find other and similar examples.

In Hugo 0.42 we added theme composition/inheritance, which is powered by Afero. We have one filesystem for templates. So I can say give me “_default/single.html” and it will give me the correct version. But there are times when I need to know the real absolute filename to this file on disk (the new SASS/SCSS feature is one example. Libsass doesn’t know about Hugo’s virtual filesystems).

So all of these filesystems supports the filesystems.RealFilenameInfo interface, which will reveal the real filename.

Thanks a lot !

I will dig deeper more hardly.