本文整理汇总了Golang中github.com/daviddengcn/sophie.FsPath.Stat方法的典型用法代码示例。如果您正苦于以下问题:Golang FsPath.Stat方法的具体用法?Golang FsPath.Stat怎么用?Golang FsPath.Stat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/daviddengcn/sophie.FsPath
的用法示例。
在下文中一共展示了FsPath.Stat方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ReadAsByteOffs
// ReadAsByteOffs reads a kv file as a slice of buffer and some int slices
// of key offsets, key ends, value offsets, and value ends.
func ReadAsByteOffs(fp sophie.FsPath) (buffer villa.ByteSlice,
keyOffs, keyEnds, valOffs, valEnds villa.IntSlice, err error) {
fi, err := fp.Stat()
if err != nil {
return nil, nil, nil, nil, nil, err
}
reader, err := fp.Open()
if err != nil {
return nil, nil, nil, nil, nil, err
}
defer reader.Close()
buffer = make([]byte, fi.Size())
if n, err := reader.Read(buffer); n != len(buffer) || err != nil {
if err != nil {
return nil, nil, nil, nil, nil, err
}
return nil, nil, nil, nil, nil, errors.New(fmt.Sprintf(
"Expected %d bytes, but only read %d bytes", len(buffer), n))
}
buf := countReadCloser(villa.NewPByteSlice(buffer))
for buf.Pos < int64(len(buffer)) {
var l sophie.VInt
if err := (&l).ReadFrom(buf, -1); err != nil {
log.Printf("Failed to read key-lenth: %v", err)
return nil, nil, nil, nil, nil, sophie.ErrBadFormat
}
keyOffs = append(keyOffs, int(buf.Pos))
if _, err := buf.Skip(int64(l)); err != nil {
log.Printf("Failed to skip key: %v", err)
return nil, nil, nil, nil, nil, sophie.ErrBadFormat
}
keyEnds = append(keyEnds, int(buf.Pos))
if err := (&l).ReadFrom(buf, -1); err != nil {
log.Printf("Failed to read value-lenth: %v", err)
return nil, nil, nil, nil, nil, sophie.ErrBadFormat
}
valOffs = append(valOffs, int(buf.Pos))
if _, err := buf.Skip(int64(l)); err != nil {
log.Printf("Failed to skip value: %v", err)
return nil, nil, nil, nil, nil, sophie.ErrBadFormat
}
valEnds = append(valEnds, int(buf.Pos))
}
return
}