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


Golang io.ReadSeeker类代码示例

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


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

示例1: GetRawTileFromMetatile

func GetRawTileFromMetatile(r io.ReadSeeker, coord gopnik.TileCoord) ([]byte, error) {
	ml, err := decodeMetatileHeader(r)
	if err != nil {
		return nil, err
	}

	size := int32(math.Sqrt(float64(ml.Count)))
	index := (int32(coord.X)-ml.X)*size + (int32(coord.Y) - ml.Y)
	if index >= ml.Count {
		return nil, fmt.Errorf("Invalid index %v/%v", index, ml.Count)
	}
	entry := ml.Index[index]
	if entry.Size > MAXENTRYSIZE {
		return nil, fmt.Errorf("entry size > MAXENTRYSIZE (size: %v)", entry.Size)
	}
	r.Seek(int64(entry.Offset), 0)
	buf := make([]byte, entry.Size)
	l, err := r.Read(buf)
	if err != nil {
		return nil, err
	}
	if int32(l) != entry.Size {
		return nil, fmt.Errorf("Invalid tile seze: %v != %v", l, entry.Size)
	}
	return buf, nil
}
开发者ID:mikhailborodin,项目名称:gopnik,代码行数:26,代码来源:metatile.go

示例2: NewFS

func NewFS(r io.ReadSeeker) *FS {
	bpb32 := &BPB32{}
	err := binary.Read(r, binary.LittleEndian, bpb32)
	if err != nil {
		// TODO error handling
	}

	fs := &FS{bpb32, UnknownType, r}
	t := fs.DetermineType()
	switch t {
	case FAT32:
		fs.Type = FAT32
		return fs
	case FAT12, FAT16:
		// reread the BPB, this time for the correct fs type
		bpb16 := &BPB16{}
		r.Seek(0, 0)
		err := binary.Read(r, binary.LittleEndian, bpb16)
		if err != nil {
			// TODO error handling
		}
		bpb32 = &BPB32{bpb16.BPBBase, BPB32Base{0, 0, 0, 0, 0, 0, [12]byte{}}, bpb16.BPB16Base}
		fs = &FS{bpb32, t, r}
	}

	return fs
}
开发者ID:dominikh,项目名称:go-vfat,代码行数:27,代码来源:vfat.go

示例3: Load

func (t *TarInfo) Load(file io.ReadSeeker) {
	var reader *tar.Reader
	file.Seek(0, 0)
	gzipReader, err := gzip.NewReader(file)
	if err != nil {
		// likely not a gzip compressed file
		file.Seek(0, 0)
		reader = tar.NewReader(file)
	} else {
		reader = tar.NewReader(gzipReader)
	}
	for {
		header, err := reader.Next()
		if err == io.EOF {
			// end of tar file
			break
		} else if err != nil {
			// error occured
			logger.Debug("[TarInfoLoad] Error when reading tar stream tarsum. Disabling TarSum, TarFilesInfo. Error: %s", err.Error())
			t.Error = TarError(err.Error())
			return
		}
		t.TarSum.Append(header, reader)
		t.TarFilesInfo.Append(header)
	}
}
开发者ID:hqm,项目名称:go-docker-registry,代码行数:26,代码来源:tar.go

示例4: ReadLine

func ReadLine(file io.ReadSeeker) (string, error) {
	localBuffer := make([]byte, 0)
	offset, err := file.Seek(0, 1)
	if err != nil {
		return "", err
	}
	if lastOffset != offset {
		nextIndex = bufferSize
	}
	for {
		newChar, err := getNext(file)
		if err != nil {
			return "", err
		}
		localBuffer = append(localBuffer, newChar)
		if newChar == '\n' {
			offset += len(localBuffer)
			lastOffset = offset
			_, err = file.Seek(offset, 0)
			if err != nil {
				return "", err
			}
			return string(localBuffer), nil
		}
	}
}
开发者ID:bjh83,项目名称:pdfstrip,代码行数:26,代码来源:util.go

示例5: retryRequest

func (p *putter) retryRequest(method, urlStr string, body io.ReadSeeker, h http.Header) (resp *http.Response, err error) {
	for i := 0; i < p.c.NTry; i++ {
		var req *http.Request
		req, err = http.NewRequest(method, urlStr, body)
		if err != nil {
			return
		}
		for k := range h {
			for _, v := range h[k] {
				req.Header.Add(k, v)
			}
		}

		p.b.Sign(req)
		resp, err = p.c.Client.Do(req)
		if err == nil {
			return
		}
		logger.debugPrintln(err)
		if body != nil {
			if _, err = body.Seek(0, 0); err != nil {
				return
			}
		}
	}
	return
}
开发者ID:reem,项目名称:s3gof3r,代码行数:27,代码来源:putter.go

示例6: init

func (table *hheaTable) init(file io.ReadSeeker, entry *tableDirEntry) (err error) {
	if _, err = file.Seek(int64(entry.offset), os.SEEK_SET); err != nil {
		return
	}
	// No advantage to using a buffered reader here.
	if err = table.version.Read(file); err != nil {
		return
	}
	err = readValues(file,
		&table.ascent,
		&table.descent,
		&table.lineGap,
		&table.advanceWidthMax,
		&table.minLeftSideBearing,
		&table.minRightSideBearing,
		&table.xMaxExtent,
		&table.caretSlopeRise,
		&table.caretSlopeRun,
		&table.caretOffset,
		&table.reserved1,
		&table.reserved2,
		&table.reserved3,
		&table.reserved4,
		&table.metricDataFormat,
		&table.numOfLongHorMetrics,
	)
	return
}
开发者ID:mohamedhasan1991,项目名称:leadtype,代码行数:28,代码来源:hhea_table.go

示例7: ChooseCompressAlgo

func ChooseCompressAlgo(path string, rs io.ReadSeeker) (AlgorithmType, error) {
	buf := make([]byte, Threshold)

	bytesRead, err := rs.Read(buf)
	if err != nil {
		return AlgoNone, err
	}

	if _, errSeek := rs.Seek(0, os.SEEK_SET); err != nil {
		return AlgoNone, errSeek
	}

	mime := guessMime(path, buf)
	compressAble := isCompressable(mime)

	if !compressAble || int64(bytesRead) != Threshold {
		return AlgoNone, nil
	}

	if strings.HasPrefix(mime, "text/") {
		return AlgoLZ4, nil
	} else {
		return AlgoSnappy, nil
	}
}
开发者ID:disorganizer,项目名称:brig,代码行数:25,代码来源:heuristic.go

示例8: getFirstRealFrameOffset

// Skips both the ID3V2 tags and optional VBR headers
func getFirstRealFrameOffset(src io.ReadSeeker) (int64, error) {
	var hdr FrameHeader
	var xing XingHeader

	off, err := getFirstFrameOffset(src)
	if err != nil {
		return 0, err
	}

	_, err = src.Seek(off, 0)
	if err != nil {
		return 0, err
	}

	bs := make([]byte, 8192)

	_, err = io.ReadAtLeast(src, bs, 4)
	if err != nil {
		return 0, err
	}

	err = hdr.Parse(bs)
	if err != nil {
		return 0, err
	}

	if xing.Parse(bs[:int(hdr.Size)]) {
		return off + hdr.Size, nil
	}

	return off, nil
}
开发者ID:san4eloostrov,项目名称:mp3,代码行数:33,代码来源:stripped.go

示例9: checkSignature

func checkSignature(ks *Keystore, prefix string, signed, signature io.ReadSeeker) (*openpgp.Entity, error) {
	acidentifier, err := types.NewACIdentifier(prefix)
	if err != nil {
		return nil, err
	}
	keyring, err := ks.loadKeyring(acidentifier.String())
	if err != nil {
		return nil, fmt.Errorf("keystore: error loading keyring %v", err)
	}
	entities, err := openpgp.CheckArmoredDetachedSignature(keyring, signed, signature)
	if err == io.EOF {
		// When the signature is binary instead of armored, the error is io.EOF.
		// Let's try with binary signatures as well
		if _, err := signed.Seek(0, 0); err != nil {
			return nil, fmt.Errorf("error seeking ACI file: %v", err)
		}
		if _, err := signature.Seek(0, 0); err != nil {
			return nil, fmt.Errorf("error seeking signature file: %v", err)
		}
		entities, err = openpgp.CheckDetachedSignature(keyring, signed, signature)
	}
	if err == io.EOF {
		// otherwise, the client failure is just "EOF", which is not helpful
		return nil, fmt.Errorf("keystore: no valid signatures found in signature file")
	}
	return entities, err
}
开发者ID:ChengTiesheng,项目名称:rkt,代码行数:27,代码来源:keystore.go

示例10: init

func (table *headTable) init(file io.ReadSeeker, entry *tableDirEntry) (err error) {
	if _, err = file.Seek(int64(entry.offset), os.SEEK_SET); err != nil {
		return
	}
	// No advantage to using a buffered reader here.
	if err = table.version.Read(file); err != nil {
		return
	}
	if err = table.fontRevision.Read(file); err != nil {
		return
	}
	err = readValues(file,
		&table.checkSumAdjustment,
		&table.magicNumber,
		&table.flags,
		&table.unitsPerEm,
		&table.created,
		&table.modified,
		&table.xMin,
		&table.yMin,
		&table.xMax,
		&table.yMax,
		&table.macStyle,
		&table.lowestRecPPEM,
		&table.fontDirectionHint,
		&table.indexToLocFormat,
		&table.glyphDataFormat,
	)
	return
}
开发者ID:mohamedhasan1991,项目名称:leadtype,代码行数:30,代码来源:head_table.go

示例11: NewMp4Media

func NewMp4Media(reader io.ReadSeeker) (fd *Mp4Media, err error) {
	fd = &Mp4Media{}
	h := next_box_header(reader)
	ftyp := next_box_body(reader, h).to_ftyp()
	fd.brand = string(ftyp.major_brand[:])
	log.Println(h.box_type(), ftyp.major_brand)

L:
	for {
		h = next_box_header(reader)
		if h.size == 0 {
			break
		}
		switch string(h.typ[:]) {
		default:
			reader.Seek(int64(h.body_size), 1)
		case "moov":
			//			mo, _ := reader.Seek(0, 1)
			//			fd.moov_offset = mo - (h.size - h.body_size)
			fd.moov_body_length = h.body_size
			fd.from_moov(next_box_body(reader, h))
			break L
		case "mdat":
			//			mo, _ := reader.Seek(0, 1)
			//			fd.mdat_offset = mo - (h.size - h.body_size)
			fd.mdat_body_length = h.body_size
			reader.Seek(int64(h.body_size), 1)
		}
	}
	return
}
开发者ID:heartszhang,项目名称:mp4box,代码行数:31,代码来源:mp4_media.go

示例12: dumpChunk

// dumpChunk extracts a compressed chunk from the given reader and
// dumps its NBT tag contents.
func dumpChunk(w io.Writer, r io.ReadSeeker, offset int64) error {
	address := offset*sectorSize + 4
	_, err := r.Seek(address, 0)
	if err != nil {
		return err
	}

	var scheme [1]byte
	_, err = io.ReadFull(r, scheme[:])
	if err != nil {
		return err
	}

	var rr io.ReadCloser
	switch scheme[0] {
	case 1:
		rr, err = gzip.NewReader(r)
	case 2:
		rr, err = zlib.NewReader(r)
	default:
		return fmt.Errorf("chunk(%d); invalid compression scheme: %d", offset, scheme[0])
	}

	if err != nil {
		return err
	}

	err = dump(w, rr)
	rr.Close()
	return err
}
开发者ID:trichner,项目名称:mctools,代码行数:33,代码来源:region.go

示例13: compile

func compile(source io.ReadSeeker, targetname string) os.Error {
	O, err := getArchSym()
	if err != nil {
		return err
	}
	gc := O + "g"
	gl := O + "l"
	tempobj := path.Join(os.TempDir(), targetname+"."+O)

	_, err = source.Seek(0, 0)
	if err != nil {
		return err
	}
	bufsource := bufio.NewReader(source)
	var insource io.Reader = bufsource
	if line, err := bufsource.ReadString('\n'); err != nil && err != os.EOF ||
		len(line) < 2 || line[:2] != "#!" {
		_, err := source.Seek(0, 0)
		if err != nil {
			return err
		}
		insource = source
	}

	err = run(gc, []string{gc, "-o", tempobj, "/dev/stdin"}, insource)
	if err != nil {
		return err
	}
	err = run(gl, []string{gl, "-o", path.Join(storedir, targetname),
		tempobj},
		nil)
	return err
}
开发者ID:Melvar,项目名称:gorun,代码行数:33,代码来源:compile.go

示例14: readPreChunk

func (cOff chunkOffTs) readPreChunk(r io.ReadSeeker) (*preChunk, error) {
	pc := preChunk{ts: cOff.ts}

	if _, err := r.Seek(cOff.offset, 0); err != nil {
		return nil, err
	}

	lr := io.LimitReader(r, cOff.size)

	var length uint32
	if err := binary.Read(lr, binary.BigEndian, &length); err != nil {
		return nil, err
	}
	lr = io.LimitReader(lr, int64(length))

	compType, err := kagus.ReadByte(lr)
	if err != nil {
		return nil, err
	}
	pc.compression = compType

	buf := new(bytes.Buffer)
	if _, err := io.Copy(buf, lr); err != nil {
		return nil, err
	}
	pc.data = buf.Bytes()

	return &pc, err

}
开发者ID:kch42,项目名称:gomcmap,代码行数:30,代码来源:regionfile.go

示例15: newOffsetReader

func newOffsetReader(buf io.ReadSeeker, offset int64) *offsetReader {
	reader := &offsetReader{}
	buf.Seek(offset, 0)

	reader.buf = buf
	return reader
}
开发者ID:CadeLaRen,项目名称:docker-3,代码行数:7,代码来源:offset_reader.go


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