本文整理汇总了Golang中io.ReadWriteSeeker.Write方法的典型用法代码示例。如果您正苦于以下问题:Golang ReadWriteSeeker.Write方法的具体用法?Golang ReadWriteSeeker.Write怎么用?Golang ReadWriteSeeker.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.ReadWriteSeeker
的用法示例。
在下文中一共展示了ReadWriteSeeker.Write方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Decompress
func Decompress(infile, outfile io.ReadWriteSeeker, passwd string, cb Callback) (err error) {
decoder := NewDecoder(infile)
if len(passwd) > 0 {
decoder.SetPassword(passwd)
}
info := Info{}
if err = decoder.GetInfo(&info, 0); err != nil {
return
}
smpSize := info.nch * ((info.bps + 7) / 8)
dataSize := info.samples * smpSize
waveHdr := WaveHeader{
chunkId: riffSign,
chunkSize: dataSize + 36,
format: waveSign,
subchunkId: fmtSign,
subchunkSize: 16,
audioFormat: 1,
numChannels: uint16(info.nch),
sampleRate: info.sps,
bitsPerSample: uint16(info.bps),
byteRate: info.sps * smpSize,
blockAlign: uint16(smpSize),
}
if err = waveHdr.Write(outfile, dataSize); err != nil {
return
}
bufSize := pcmBufferLength * smpSize
buffer := make([]byte, bufSize)
var writeLen int
for {
if writeLen = int(uint32(decoder.ProcessStream(buffer, cb)) * smpSize); writeLen == 0 {
break
}
buf := buffer[:writeLen]
if writeLen, err = outfile.Write(buf); err != nil {
return
} else if writeLen != len(buf) {
err = errPartialWritten
return
}
}
return
}
示例2: 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
}