本文整理匯總了Golang中github.com/kurrik/fauxfile.File.Stat方法的典型用法代碼示例。如果您正苦於以下問題:Golang File.Stat方法的具體用法?Golang File.Stat怎麽用?Golang File.Stat使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/kurrik/fauxfile.File
的用法示例。
在下文中一共展示了File.Stat方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: unyaml
// Deserializes the yaml file at the given path to the supplied object.
func (gw *GhostWriter) unyaml(path string, out interface{}) (err error) {
var (
file fauxfile.File
info os.FileInfo
data []byte
)
if file, err = gw.fs.Open(path); err != nil {
return
}
defer file.Close()
if info, err = file.Stat(); err != nil {
return
}
data = make([]byte, info.Size())
if _, err = file.Read(data); err != nil {
return
}
err = yaml.Unmarshal(data, out)
return
}
示例2: ReadFile
func ReadFile(fs fauxfile.Filesystem, path string) (data string, err error) {
var (
f fauxfile.File
fi os.FileInfo
)
if f, err = fs.Open(path); err != nil {
return
}
defer f.Close()
if fi, err = f.Stat(); err != nil {
return
}
buf := make([]byte, fi.Size())
if _, err = f.Read(buf); err != nil {
if err != io.EOF {
return
}
err = nil
}
data = string(buf)
return
}
示例3: readFile
// Reads a file from the given path and returns a string of the contents.
func (ts *Templates) readFile(path string) (out string, err error) {
var (
f fauxfile.File
fi os.FileInfo
buf []byte
)
if f, err = ts.fs.Open(path); err != nil {
return
}
defer f.Close()
if fi, err = f.Stat(); err != nil {
return
}
buf = make([]byte, fi.Size())
if _, err = f.Read(buf); err != nil {
if err != io.EOF {
return
}
err = nil
}
out = string(buf)
return
}
示例4: copyFile
// Copies the file at path src to path dst.
// Returns the number of bytes written or an error if it occurred.
func (gw *GhostWriter) copyFile(src string, dst string) (n int64, err error) {
var (
fdst fauxfile.File
fsrc fauxfile.File
fi os.FileInfo
)
if fsrc, err = gw.fs.Open(src); err != nil {
return
}
defer func() {
if err := fsrc.Close(); err != nil {
gw.log.Printf("Problem closing %v: %v\n", src, err)
} else {
gw.log.Printf("Closed %v\n", src)
}
}()
if fdst, err = gw.fs.Create(dst); err != nil {
return
}
defer func() {
if err := fdst.Close(); err != nil {
gw.log.Printf("Problem closing %v: %v\n", dst, err)
} else {
gw.log.Printf("Closed %v\n", dst)
}
}()
if fi, err = fsrc.Stat(); err != nil {
return
}
fdst.Chmod(fi.Mode())
_, err = io.Copy(fdst, fsrc)
return
}