本文整理匯總了Golang中io.ReaderAt.Stat方法的典型用法代碼示例。如果您正苦於以下問題:Golang ReaderAt.Stat方法的具體用法?Golang ReaderAt.Stat怎麽用?Golang ReaderAt.Stat使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類io.ReaderAt
的用法示例。
在下文中一共展示了ReaderAt.Stat方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: HasEOF
// HasEOF checks for the presence of a BGZF magic EOF block.
// The magic block is defined in the SAM specification. A magic block
// is written by a Writer on calling Close. The ReaderAt must provide
// some method for determining valid ReadAt offsets.
func HasEOF(r io.ReaderAt) (bool, error) {
type sizer interface {
Size() int64
}
type stater interface {
Stat() (os.FileInfo, error)
}
type lenSeeker interface {
io.Seeker
Len() int
}
var size int64
switch r := r.(type) {
case sizer:
size = r.Size()
case stater:
fi, err := r.Stat()
if err != nil {
return false, err
}
size = fi.Size()
case lenSeeker:
var err error
size, err = r.Seek(0, 1)
if err != nil {
return false, err
}
size += int64(r.Len())
default:
return false, ErrNoEnd
}
b := make([]byte, len(magicBlock))
_, err := r.ReadAt(b, size-int64(len(magicBlock)))
if err != nil {
return false, err
}
for i, c := range b {
if c != magicBlock[i] {
return false, nil
}
}
return true, nil
}