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


Golang io.WriterAt类代码示例

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


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

示例1: checkSumAdjust

func checkSumAdjust(w io.WriterAt, head []int64, checksum ULONG) {
	adjust := make([]byte, 4)
	binary.BigEndian.PutUint32(adjust, uint32(checkSumAdjustmentMagic-checksum))
	for _, offs := range head {
		w.WriteAt(adjust, offs+8)
	}
}
开发者ID:mandel59,项目名称:gofont,代码行数:7,代码来源:sfnt.go

示例2: write

func write(fp io.WriterAt,
	c *cache.CacheMap,
	devid, offset, blocks uint32,
	buffer []byte) {

	here := make(chan *message.Message, blocks)
	cacheoffset := cache.Address64(cache.Address{Devid: devid, Block: offset})

	// Send invalidates for each block
	iopkt := &message.IoPkt{
		Address: cacheoffset,
		Blocks:  blocks,
	}
	c.Invalidate(iopkt)

	// Write to storage back end
	// :TODO: check return status
	fp.WriteAt(buffer, int64(offset)*4*KB)

	// Now write to cache
	msg := message.NewMsgPut()
	msg.RetChan = here
	iopkt = msg.IoPkt()
	iopkt.Blocks = blocks
	iopkt.Address = cacheoffset
	iopkt.Buffer = buffer
	c.Put(msg)

	<-here
}
开发者ID:chenweicai,项目名称:pblcache,代码行数:30,代码来源:cacheio.go

示例3: dumpDirty

func (f *bitFiler) dumpDirty(w io.WriterAt) (nwr int, err error) {
	f.link()
	for pgI, pg := range f.m {
		if !pg.dirty {
			continue
		}

		for pg.prev != nil && pg.prev.dirty {
			pg = pg.prev
			pgI--
		}

		for pg != nil && pg.dirty {
			if _, err := w.WriteAt(pg.data, pgI<<bfBits); err != nil {
				return 0, err
			}

			nwr++
			pg.dirty = false
			pg = pg.next
			pgI++
		}
	}
	return
}
开发者ID:brgmnn,项目名称:syncthing,代码行数:25,代码来源:xact.go

示例4: writeTables

func writeTables(table []Table, w io.WriterAt, offset int64) (map[Table]*OffsetEntry, []int64, ULONG, error) {
	total := ULONG(0)
	entryMap := make(map[Table]*OffsetEntry)
	head := make([]int64, 0)
	for _, v := range table {
		t := v.Tag()
		ts := t.String()
		if ts == "head" {
			head = append(head, offset)
		}
		bytes := v.Bytes()
		checksum := calcCheckSum(bytes)
		length := len(bytes)
		if _, err := w.WriteAt(bytes, offset); err != nil {
			return nil, nil, 0, err
		}
		entryMap[v] = &OffsetEntry{
			t,
			checksum,
			ULONG(offset),
			ULONG(length),
		}
		offset = roundUp(offset + int64(length))
		total += checksum
	}
	return entryMap, head, total, nil
}
开发者ID:mandel59,项目名称:gofont,代码行数:27,代码来源:sfnt.go

示例5: ItemValWrite

func (o *Store) ItemValWrite(c *Collection, i *Item, w io.WriterAt, offset int64) error {
	if o.callbacks.ItemValWrite != nil {
		return o.callbacks.ItemValWrite(c, i, w, offset)
	}
	_, err := w.WriteAt(i.Val, offset)
	return err
}
开发者ID:frankwmoyer,项目名称:gkvlite,代码行数:7,代码来源:store.go

示例6: WriteToWriterAt

func (g *getter) WriteToWriterAt(w io.WriterAt) (int, error) {
	fileOffsetMap := make(map[string]int64)
	filePosition := int64(0)
	totalWritten := int(0)

	for chunk := range g.readCh {
		fileOffset, present := fileOffsetMap[chunk.path]
		if !present {
			fileOffset = filePosition
			fileOffsetMap[chunk.path] = filePosition
			filePosition += chunk.fileSize
		}

		var chunkWritten int = 0
		for int64(chunkWritten) < chunk.size {
			n, err := w.WriteAt(chunk.b[:chunk.size], fileOffset+chunk.start)
			chunkWritten += n
			totalWritten += n
			if err != nil {
				return totalWritten, err
			}
		}

		g.sp.give <- chunk.b
	}
	return totalWritten, nil
}
开发者ID:haspatrickl,项目名称:s3gof3r,代码行数:27,代码来源:getter.go

示例7: Write

func (self *rlewrite) Write(b io.WriterAt) (err error) {
	s := make([]byte, self.num)
	for i := range s {
		s[i] = self.data
	}
	_, err = b.WriteAt(s, int64(self.start))
	return
}
开发者ID:zephyrtronium,项目名称:multips,代码行数:8,代码来源:ips.go

示例8: writeNumRecs

func writeNumRecs(w io.WriterAt, numrecs int64) error {
	if numrecs >= (1<<31) || numrecs < 0 {
		numrecs = -1
	}
	buf := [4]byte{byte(numrecs >> 24), byte(numrecs >> 16), byte(numrecs >> 8), byte(numrecs)}
	_, err := w.WriteAt(buf[:], _NumRecsOffset)
	return err
}
开发者ID:lvdlvd,项目名称:go-cdf,代码行数:8,代码来源:numrecs.go

示例9: writeAtWithBuffer

func writeAtWithBuffer(w io.WriterAt, str string, off int64) (int, error) {
	n := len(str)
	extendAndSliceBuffer(n)
	for i := 0; i < n; i++ {
		buffer[i] = str[i]
	}
	return w.WriteAt(buffer, off)
}
开发者ID:joshlf,项目名称:stringio,代码行数:8,代码来源:stringio.go

示例10: writeFontsOffset

func writeFontsOffset(w io.WriterAt, offset int64, fonts TTCOffsetTable) (ULONG, error) {
	buf := new(bytes.Buffer)
	binary.Write(buf, binary.BigEndian, fonts)
	bytes := buf.Bytes()
	if _, err := w.WriteAt(bytes, offset); err != nil {
		return 0, err
	}
	return calcCheckSum(bytes), nil
}
开发者ID:mandel59,项目名称:gofont,代码行数:9,代码来源:ttc.go

示例11: writeAt

func writeAt(w io.WriterAt, i interface{}, offset int64) (ULONG, int64, error) {
	buf := new(bytes.Buffer)
	binary.Write(buf, binary.BigEndian, i)
	bytes := buf.Bytes()
	if _, err := w.WriteAt(bytes, offset); err != nil {
		return 0, 0, err
	}
	return calcCheckSum(bytes), offset + int64(len(bytes)), nil
}
开发者ID:mandel59,项目名称:gofont,代码行数:9,代码来源:sfnt.go

示例12: WriteData

func (info *blockListInfo) WriteData(writer io.WriterAt, data []byte) error {
	//Writes the data to the location specified by the info/entry
	if info.Entry.Free == 0 {
		return errors.New("Info is free, unable to write")
	}
	if int64(binary.Size(data)) != info.Entry.Size {
		return errors.New("Size of data is incorrect for size of info.")
	}
	_, err := writer.WriteAt(data, info.Entry.Start)
	return err
}
开发者ID:finder,项目名称:gokvlite,代码行数:11,代码来源:filemanager.go

示例13: dumpDirty

func (f *bitFiler) dumpDirty(w io.WriterAt) (nwr int, err error) {
	f.Lock()
	defer f.Unlock()
	f.link()
	for pgI, pg := range f.m {
		if !pg.dirty {
			continue
		}

		for pg.prev != nil && pg.prev.dirty {
			pg = pg.prev
			pgI--
		}

		for pg != nil && pg.dirty {
			last := false
			var off int64
			first := -1
			for i := 0; i < bfSize; i++ {
				flag := pg.flags[i>>3]&bitmask[i&7] != 0
				switch {
				case flag && !last: // Leading edge detected
					off = pgI<<bfBits + int64(i)
					first = i
				case !flag && last: // Trailing edge detected
					n, err := w.WriteAt(pg.data[first:i], off)
					if n != i-first {
						return 0, err
					}
					first = -1
					nwr++
				}

				last = flag
			}
			if first >= 0 {
				i := bfSize
				n, err := w.WriteAt(pg.data[first:i], off)
				if n != i-first {
					return 0, err
				}

				nwr++
			}

			pg.dirty = false
			pg = pg.next
			pgI++
		}
	}
	return
}
开发者ID:letiemble,项目名称:syncthing,代码行数:52,代码来源:xact.go

示例14: applyContent

func applyContent(cc <-chan content, dst io.WriterAt) error {
	var err error

	for c := range cc {
		_, err = dst.WriteAt(c.data, c.offset)
		buffers.Put(c.data)
		if err != nil {
			return err
		}
	}

	return nil
}
开发者ID:philips,项目名称:syncthing,代码行数:13,代码来源:model_puller.go

示例15: fill

func fill(w io.WriterAt, begin, end int64, val interface{}, dtype datatype) error {
	var buf bytes.Buffer
	binary.Write(&buf, binary.BigEndian, val)
	if buf.Len() != dtype.storageSize() {
		panic("invalid fill value")
	}
	d := int64(buf.Len())
	for ; begin < end; begin += d {
		if _, err := w.WriteAt(buf.Bytes(), begin); err != nil {
			return err
		}
	}
	return nil
}
开发者ID:lvdlvd,项目名称:go-cdf,代码行数:14,代码来源:file.go


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