github.com/aarzilli/tools@v0.0.0-20151123112009-0d27094f75e0/os/fsi/common/convenience.go (about)

     1  package common
     2  
     3  import (
     4  	"os"
     5  
     6  	"github.com/pbberlin/tools/os/fsi"
     7  )
     8  
     9  func WriteFile(fs fsi.FileSystem, fn string, b []byte) error {
    10  
    11  	dir, _ := fs.SplitX(fn)
    12  
    13  	err := fs.MkdirAll(dir, os.ModePerm)
    14  	if err != nil && err != fsi.ErrFileExists {
    15  		return err
    16  	}
    17  
    18  	err = fs.WriteFile(fn, b, 0)
    19  	if err != nil {
    20  		return err
    21  	}
    22  
    23  	return nil
    24  }