本文整理匯總了Golang中io.SectionReader.Size方法的典型用法代碼示例。如果您正苦於以下問題:Golang SectionReader.Size方法的具體用法?Golang SectionReader.Size怎麽用?Golang SectionReader.Size使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類io.SectionReader
的用法示例。
在下文中一共展示了SectionReader.Size方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: readCompressed
func readCompressed(r *io.SectionReader, offset int64, s []byte) (int, error) {
zr, err := zlib.NewReader(io.NewSectionReader(r, offset, r.Size()-offset))
if err != nil {
return 0, err
}
return io.ReadFull(zr, s)
}
示例2: nextAtom
func nextAtom(sr *io.SectionReader) (string, *io.SectionReader, error) {
var asz uint32
var sz int64
atyp := make([]byte, 4)
if err := binary.Read(sr, binary.BigEndian, &asz); err != nil {
return "", nil, err
}
if asz == 0 {
// Size is entire section
sz = sr.Size()
} else if asz == 1 {
return "", nil, ErrNotImplemented
} else {
sz = int64(asz)
}
if _, err := io.ReadFull(sr, atyp); err != nil {
return "", nil, err
}
sz = sz - 8 // 4 bytes for size, 4 bytes for type
// Get current offset
cur, err := seekCur(sr)
if err != nil {
return "", nil, err
}
// Consume remainder of parent
if _, err := io.CopyN(ioutil.Discard, sr, sz); err != nil {
return "", nil, err
}
return string(atyp), io.NewSectionReader(sr, cur, sz), nil
}
示例3: hashCore
// hashCore hashes a SectionReader using the ImoHash parameters.
func (imo *ImoHash) hashCore(f *io.SectionReader) [Size]byte {
var result [Size]byte
imo.hasher.Reset()
if f.Size() < int64(imo.sampleThreshold) || imo.sampleSize < 1 {
buffer := make([]byte, f.Size())
f.Read(buffer)
imo.hasher.Write(buffer)
} else {
buffer := make([]byte, imo.sampleSize)
f.Read(buffer)
imo.hasher.Write(buffer)
f.Seek(f.Size()/2, 0)
f.Read(buffer)
imo.hasher.Write(buffer)
f.Seek(int64(-imo.sampleSize), 2)
f.Read(buffer)
imo.hasher.Write(buffer)
}
hash := imo.hasher.Sum(nil)
binary.PutUvarint(hash, uint64(f.Size()))
copy(result[:], hash)
return result
}