本文整理汇总了Golang中io.ReadWriteSeeker.Seek方法的典型用法代码示例。如果您正苦于以下问题:Golang ReadWriteSeeker.Seek方法的具体用法?Golang ReadWriteSeeker.Seek怎么用?Golang ReadWriteSeeker.Seek使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.ReadWriteSeeker
的用法示例。
在下文中一共展示了ReadWriteSeeker.Seek方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: hashCopyN
// hashCopyN - Calculates Md5sum and SHA256sum for upto partSize amount of bytes.
func (c Client) hashCopyN(writer io.ReadWriteSeeker, reader io.Reader, partSize int64) (md5Sum, sha256Sum []byte, size int64, err error) {
// MD5 and SHA256 hasher.
var hashMD5, hashSHA256 hash.Hash
// MD5 and SHA256 hasher.
hashMD5 = md5.New()
hashWriter := io.MultiWriter(writer, hashMD5)
if c.signature.isV4() {
hashSHA256 = sha256.New()
hashWriter = io.MultiWriter(writer, hashMD5, hashSHA256)
}
// Copies to input at writer.
size, err = io.CopyN(hashWriter, reader, partSize)
if err != nil {
// If not EOF return error right here.
if err != io.EOF {
return nil, nil, 0, err
}
}
// Seek back to beginning of input, any error fail right here.
if _, err := writer.Seek(0, 0); err != nil {
return nil, nil, 0, err
}
// Finalize md5shum and sha256 sum.
md5Sum = hashMD5.Sum(nil)
if c.signature.isV4() {
sha256Sum = hashSHA256.Sum(nil)
}
return md5Sum, sha256Sum, size, err
}
示例2: ReadRawRecord
// ReadRawRecord reads a raw record from the provided file.
//
// On error, err will no non-nil. Expected error values are io.EOF
// when the end of the file has been reached or io.ErrUnexpectedEOF if
// a complete record was unable to be read.
//
// In the case of io.ErrUnexpectedEOF the file offset will be reset
// back to where it was upon entering this function so it is ready to
// be read from again if it is expected more data will be written to
// the file.
func ReadRawRecord(file io.ReadWriteSeeker) (*RawRecord, error) {
var header RawHeader
/* Get the current offset so we can seek back to it. */
offset, _ := file.Seek(0, 1)
/* Now read in the header. */
err := binary.Read(file, binary.BigEndian, &header)
if err != nil {
file.Seek(offset, 0)
return nil, err
}
/* Create a buffer to hold the raw record data and read the
/* record data into it */
data := make([]byte, header.Len)
n, err := file.Read(data)
if err != nil {
file.Seek(offset, 0)
return nil, err
}
if uint32(n) != header.Len {
file.Seek(offset, 0)
return nil, io.ErrUnexpectedEOF
}
return &RawRecord{header.Type, data}, nil
}
示例3: Save
func (geneMap GeneMap) Save(file io.ReadWriteSeeker) (err os.Error) {
//go to the begging of the file
file.Seek(0, 0)
enc := gob.NewEncoder(file)
err = enc.Encode(lens{len(geneMap)})
for key, item := range geneMap {
enc.Encode(keyVal{key, item})
if err != nil {
panic(err.String())
}
}
return
}
示例4: newIndex
func newIndex(rw io.ReadWriteSeeker) (*storeindex, error) {
off, err := rw.Seek(0, os.SEEK_END)
if err != nil {
return nil, errwrap.Err(err, "cannot seek")
}
if off%8 != 0 {
return nil, fmt.Errorf("corrupted index store: %d", off)
}
x := &storeindex{
count: uint64(off / 8),
rw: rw,
}
return x, nil
}
示例5: AppendAdder
func AppendAdder(genome io.ReadWriteSeeker, gene genome.Gene, geneMap genome.GeneMap) (pos int64, err os.Error) {
//go to the end of the file
pos, err = genome.Seek(0, 2)
length, err := genome.Write(gene)
if err != nil {
panic(err.String())
}
genome.Seek(pos, 0)
test := make([]byte, length)
genome.Read(test)
if !bytes.Equal(gene.GetData(), test) {
panic("apperder broken")
}
return
}
示例6: insertSample
func insertSample(cfg *BuildConfig, header *OctreeHeader, readWriter io.ReadWriteSeeker, sample Sample, bounds Box, voxelRes int) error {
var node accNode
for {
if err := binary.Read(readWriter, binary.BigEndian, &node); err != nil {
return err
}
if _, err := readWriter.Seek(int64(-mipR64G64B64A64S64UnpackUI32.NodeSize()), 1); err != nil {
return err
}
color := sample.Color()
node.Color[0] += uint64(color.R * 255)
node.Color[1] += uint64(color.G * 255)
node.Color[2] += uint64(color.B * 255)
node.Color[3] += uint64(color.A * 255)
node.Color[4]++
if err := binary.Write(readWriter, binary.BigEndian, node.Color); err != nil {
return err
}
if voxelRes == 1 {
header.NumLeafs++
return nil
}
var (
childBounds Box
newVoxelRes = voxelRes
)
for i, child := range node.Children {
childBounds.Size = bounds.Size * 0.5
childOffset := childPositions[i].scale(childBounds.Size)
childBounds.Pos = bounds.Pos.add(&childOffset)
if childBounds.Intersect(sample.Position()) == true {
if child == 0 {
currentPos, err := readWriter.Seek(0, 1)
if err != nil {
return err
}
newPos, err := readWriter.Seek(0, 2)
if err != nil {
return err
}
if _, err = readWriter.Seek(currentPos, 0); err != nil {
return err
}
node.Children[i] = uint32((newPos - int64(header.Size())) / int64(mipR64G64B64A64S64UnpackUI32.NodeSize()))
if err := binary.Write(readWriter, binary.BigEndian, node.Children); err != nil {
return err
}
if _, err = readWriter.Seek(newPos, 0); err != nil {
return err
}
header.NumNodes++
var newNode accNode
if err := binary.Write(readWriter, binary.BigEndian, newNode); err != nil {
return err
}
if _, err := readWriter.Seek(int64(-mipR64G64B64A64S64UnpackUI32.NodeSize()), 1); err != nil {
return err
}
} else {
if _, err := readWriter.Seek(int64(int(child)*mipR64G64B64A64S64UnpackUI32.NodeSize()+header.Size()), 0); err != nil {
return err
}
}
newVoxelRes = voxelRes / 2
break
}
}
if newVoxelRes == voxelRes {
return nil
} else {
bounds = childBounds
voxelRes = newVoxelRes
}
}
}