當前位置: 首頁>>代碼示例>>Golang>>正文


Golang WriteSeeker.Seek方法代碼示例

本文整理匯總了Golang中io.WriteSeeker.Seek方法的典型用法代碼示例。如果您正苦於以下問題:Golang WriteSeeker.Seek方法的具體用法?Golang WriteSeeker.Seek怎麽用?Golang WriteSeeker.Seek使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.WriteSeeker的用法示例。


在下文中一共展示了WriteSeeker.Seek方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: writeAt

func writeAt(w io.WriteSeeker, c int64, p []byte) (int64, error) {
	if _, err := w.Seek(c, 0); err != nil {
		return 0, err
	}
	n, err := w.Write(p)
	return int64(n), err
}
開發者ID:haowang1013,項目名稱:kaiju,代碼行數:7,代碼來源:internals.go

示例2: writeChunk

// writeChunk writes a chunk to the given stream.
func writeChunk(w io.WriteSeeker, cd *ChunkDescriptor, offset int) error {
	// Jump to chunk sector.
	_, err := w.Seek(int64(offset)*sectorSize, 0)
	if err != nil {
		return err
	}

	// Write compressed data size.
	err = writeU32(w, uint32(len(cd.data)))
	if err != nil {
		return err
	}

	// Write compression scheme.
	err = writeU8(w, ZLib)
	if err != nil {
		return err
	}

	// Write compressed data.
	_, err = w.Write(cd.data)
	if err != nil {
		return err
	}

	// Pad data
	padding := (cd.SectorCount() * sectorSize) - len(cd.data)
	_, err = w.Write(make([]byte, padding))
	return err
}
開發者ID:trichner,項目名稱:mctools,代碼行數:31,代碼來源:region.go

示例3: writeHeader

// writeHeader writes header data into the given writer.
func writeHeader(w io.WriteSeeker, set []*ChunkDescriptor) error {
	var locations, timestamps [sectorSize]byte

	offset := 2 // Skip first two sectors for the header.

	for _, cd := range set {
		if cd == nil {
			continue
		}

		sectors := cd.SectorCount()
		writeOffset(locations[:], cd.X, cd.Z, offset, sectors)
		writeTimestamp(timestamps[:], cd.X, cd.Z, cd.LastModified)

		offset += sectors
	}

	_, err := w.Seek(0, 0)
	if err != nil {
		return err
	}

	_, err = w.Write(locations[:])
	if err != nil {
		return err
	}

	_, err = w.Write(timestamps[:])
	return err
}
開發者ID:trichner,項目名稱:mctools,代碼行數:31,代碼來源:region.go

示例4: writeBlock

// writeBlock writes a full or partial block into ws. len(p) must be smaller than (bs - crc32Len).
// Each block contains a crc32Len bytes crc32c of the payload and a (bs-crc32Len)
// bytes payload. Any error encountered is returned.
// It is caller's responsibility to ensure that only the last block in the file has
// len(p) < bs - crc32Len
func writeBlock(ws io.WriteSeeker, index, bs int64, p []byte) error {
	if int64(len(p)) > bs-crc32Len {
		return ErrPayloadSizeTooLarge
	}

	// seek to the beginning of the block
	_, err := ws.Seek(index*bs, os.SEEK_SET)
	if err != nil {
		return err
	}

	// write crc32c
	// TODO: reuse buffer
	b := make([]byte, crc32Len)
	binary.BigEndian.PutUint32(b, crc32.Checksum(p, crc32cTable))
	_, err = ws.Write(b)
	if err != nil {
		return err
	}

	// write payload
	_, err = ws.Write(p)
	if err != nil {
		return err
	}
	return nil
}
開發者ID:missmayo,項目名稱:cfs,代碼行數:32,代碼來源:block.go

示例5: write

func write(f io.WriteSeeker, s string) error {
	_, err := f.Write([]byte(s))
	if err != nil {
		return err
	}
	_, err = f.Seek(0, 0)
	return err
}
開發者ID:stengaard,項目名稱:aquactl,代碼行數:8,代碼來源:pin_linux.go

示例6: WriteEmptyInt

func WriteEmptyInt(w io.WriteSeeker, n int) (pos int64, err error) {
	if pos, err = w.Seek(0, 1); err != nil {
		return
	}
	if err = WriteInt(w, 0, n); err != nil {
		return
	}
	return
}
開發者ID:louisyoo,項目名稱:mp4,代碼行數:9,代碼來源:writer.go

示例7: Decode

func (dec decoder) Decode(x interface{}) error {
	err := dec.dec.Decode(x)
	if err != nil {
		return err
	}
	var names []string
	err = dec.dec.Decode(&names)
	if err != nil {
		return err
	}
	files := make(map[string][]*File)
	typeapply.Do(func(f *File) {
		if f != nil && f.Name != "" {
			files[f.Name] = append(files[f.Name], f)
		}
	},
		x)
	for _, name := range names {
		var out io.WriteSeeker
		if files[name] == nil {
			out = nullWriter{}
		} else {
			samefiles := files[name]
			f := samefiles[0]
			if f == nil {
				return errors.New("file not found in manifest")
			}
			f.file, err = ioutil.TempFile("", "filemarshal")
			if err != nil {
				return err
			}
			f.Name = f.file.Name()
			for _, g := range samefiles[1:] {
				*g = *f
			}
			out = f.file
		}
		for {
			buf := []byte(nil)
			err = dec.dec.Decode(&buf)
			if err != nil {
				return err
			}
			if len(buf) == 0 {
				break
			}
			_, err = out.Write(buf)
			if err != nil {
				return err
			}
		}
		out.Seek(0, 0)
	}
	return nil
}
開發者ID:zxpbenson,項目名稱:rog-go,代碼行數:55,代碼來源:filemarshal.go

示例8: download

func (s *mockedStorage) download(url string, output io.WriteSeeker) error {
	blob, ok := s.data[url]
	if !ok {
		return ErrDownloadError
	}
	_, err := output.Seek(0, os.SEEK_SET)
	s.c.So(err, ShouldBeNil)
	_, err = output.Write(blob)
	s.c.So(err, ShouldBeNil)
	return nil
}
開發者ID:nicko96,項目名稱:Chrome-Infra,代碼行數:11,代碼來源:client_test.go

示例9: copySparse

func (p *Provider) copySparse(dst io.WriteSeeker, src sparse.FileIoProcessor) error {
	extents, err := sparse.GetFiemapExtents(src)
	if err != nil {
		return err
	}

	for _, x := range extents {
		if _, err := dst.Seek(int64(x.Logical), os.SEEK_SET); err != nil {
			return err
		}
		if _, err := io.Copy(dst, io.NewSectionReader(src, int64(x.Logical), int64(x.Length))); err != nil {
			return err
		}
	}

	return nil
}
開發者ID:imjorge,項目名稱:flynn,代碼行數:17,代碼來源:zfs.go

示例10: writeMutation

// writeMutation encodes a mutation into a block and appends the
// block to the writer returning an error. Seek offset is unmodified.
func writeMutation(w io.WriteSeeker, mut string) (err error) {
	b := newBlock(mut)

	offset, _ := w.Seek(0, 1) // remember where we are.
	// We use two write calls bacause we use encoding/binary
	// to write the fixed length header.
	err = binary.Write(w, binary.LittleEndian, b.Hdr)
	if err != nil {
		return
	}

	// We'we written the header successfully, write the rest
	// of the data.
	_, err = w.Write(b.Data)
	w.Seek(offset, 0) // rewind so we don't break readMutation().
	return
}
開發者ID:nickstenning,項目名稱:doozerd,代碼行數:19,代碼來源:journal.go

示例11: Write

func (t *TLK) Write(w io.WriteSeeker) error {

	w.Seek(0, os.SEEK_SET)
	err := binary.Write(w, binary.LittleEndian, t.header)
	if err != nil {
		return err
	}
	err = binary.Write(w, binary.LittleEndian, t.entries)
	if err != nil {
		return err
	}
	w.Seek(0, os.SEEK_CUR)
	_, err = w.Write(t.stringBuf)
	if err != nil {
		return err
	}
	return nil

}
開發者ID:MasterScrat,項目名稱:bgfileformats,代碼行數:19,代碼來源:tlk.go

示例12: WriteData

// WriteData given a storage and a buffer, write the data to the storage and return a pointer to that data
func WriteData(s io.WriteSeeker, b []byte) (Pointer, error) {

	// seek to the end of the storage
	offset, err := s.Seek(0, 2)
	if err != nil {
		return Pointer{}, err
	}

	// write the buffer to storage
	err = writeFull(s, b)
	if err != nil {
		return Pointer{}, err
	}

	return Pointer{
		Addr: uint64(offset),
		Size: uint64(len(b)),
	}, nil
}
開發者ID:eliothedeman,項目名稱:serial,代碼行數:20,代碼來源:storage.go

示例13: Write

// Calc header and partitions CRC. Save Header and partition entries to the disk.
// It independent of start position: writer will be seek to position from Table.Header.
func (this Table) Write(writer io.WriteSeeker) (err error) {
	this.Header.PartitionsCRC = this.calcPartitionsCRC()
	if headerPos, ok := mul(int64(this.SectorSize), int64(this.Header.HeaderStartLBA)); ok {
		writer.Seek(headerPos, 0)
	}
	err = this.Header.write(writer, true)
	if err != nil {
		return
	}
	if partTablePos, ok := mul(int64(this.SectorSize), int64(this.Header.PartitionsTableStartLBA)); ok {
		writer.Seek(partTablePos, 0)
	}
	for _, part := range this.Partitions {
		err = part.write(writer, this.Header.PartitionEntrySize)
		if err != nil {
			return
		}
	}
	return
}
開發者ID:rekby,項目名稱:gpt,代碼行數:22,代碼來源:gpt.go

示例14: growBy

func growBy(w io.WriteSeeker, n int) {
	var err error
	defer panicIf(&err)

	// Seek to the end.
	_, err = w.Seek(0, 2)
	if err != nil {
		err = fmt.Errorf("Seek: %v", err)
		return
	}

	// Write.
	_, err = w.Write(bytes.Repeat([]byte("a"), n))
	if err != nil {
		err = fmt.Errorf("Write: %v", err)
		return
	}

	return
}
開發者ID:mbookman,項目名稱:gcsfuse,代碼行數:20,代碼來源:file_leaser_test.go

示例15: ConvertToUTF8

func (t *TLK) ConvertToUTF8(w io.WriteSeeker) error {
	w.Seek(0, os.SEEK_SET)
	err := binary.Write(w, binary.LittleEndian, t.header)
	if err != nil {
		return err
	}
	curStringOffset := 0
	strArray := []string{}
	for i := 0; i < len(t.entries); i++ {
		str, err := t.String(i)
		if err != nil {
			return err
		}
		strArray = append(strArray, str)
		t.entries[i].Offset = uint32(curStringOffset)
		t.entries[i].Length = uint32(len(str))
		curStringOffset += int(t.entries[i].Length)
		w.Seek(int64(binary.Size(t.header)+binary.Size(t.entries[0])*i), os.SEEK_SET)
		err = binary.Write(w, binary.LittleEndian, t.entries[i])
		if err != nil {
			return err
		}
	}
	w.Seek(int64(t.header.StringOffset), os.SEEK_SET)
	for _, str := range strArray {
		w.Write([]byte(str))
	}

	return nil
}
開發者ID:MasterScrat,項目名稱:bgfileformats,代碼行數:30,代碼來源:tlk.go


注:本文中的io.WriteSeeker.Seek方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。