当前位置: 首页>>代码示例>>Golang>>正文


Golang ReadWriteSeeker.Read方法代码示例

本文整理汇总了Golang中io.ReadWriteSeeker.Read方法的典型用法代码示例。如果您正苦于以下问题:Golang ReadWriteSeeker.Read方法的具体用法?Golang ReadWriteSeeker.Read怎么用?Golang ReadWriteSeeker.Read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.ReadWriteSeeker的用法示例。


在下文中一共展示了ReadWriteSeeker.Read方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: 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
}
开发者ID:cleesmith,项目名称:go-unified2,代码行数:38,代码来源:unified2.go

示例2: Compress

func Compress(infile, outfile io.ReadWriteSeeker, passwd string, cb Callback) (err error) {
	waveHdr := WaveHeader{}
	var dataSize uint32
	if dataSize, err = waveHdr.Read(infile); err != nil {
		err = errRead
		return
	} else if dataSize >= 0x7FFFFFFF {
		err = fmt.Errorf("incorrect data size info in wav file: %x", dataSize)
		return
	}
	if (waveHdr.chunkId != riffSign) ||
		(waveHdr.format != waveSign) ||
		(waveHdr.numChannels == 0) ||
		(waveHdr.numChannels > maxNCH) ||
		(waveHdr.bitsPerSample == 0) ||
		(waveHdr.bitsPerSample > maxBPS) {
		err = errFormat
		return
	}
	encoder := NewEncoder(outfile)
	smpSize := uint32(waveHdr.numChannels * ((waveHdr.bitsPerSample + 7) / 8))
	info := Info{
		nch:     uint32(waveHdr.numChannels),
		bps:     uint32(waveHdr.bitsPerSample),
		sps:     waveHdr.sampleRate,
		format:  formatSimple,
		samples: dataSize / smpSize,
	}
	if len(passwd) > 0 {
		encoder.SetPassword(passwd)
		info.format = formatEncrypted
	}
	bufSize := pcmBufferLength * smpSize
	buffer := make([]byte, bufSize)
	if err = encoder.SetInfo(&info, 0); err != nil {
		return
	}
	var readLen int
	for dataSize > 0 {
		if bufSize >= dataSize {
			bufSize = dataSize
		}
		if readLen, err = infile.Read(buffer[:bufSize]); err != nil || readLen != int(bufSize) {
			err = errRead
			return
		}
		encoder.ProcessStream(buffer[:bufSize], cb)
		dataSize -= bufSize
	}
	encoder.Close()
	return
}
开发者ID:zyxar,项目名称:tta,代码行数:52,代码来源:encoder.go

示例3: 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

}
开发者ID:ericfode,项目名称:Datazome,代码行数:17,代码来源:appendAdder.go


注:本文中的io.ReadWriteSeeker.Read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。