// calcChainReader provides a function to get the pointer to the structure
// after deserialization of xl/calcChain.xml.
492379
func (f *File) calcChainReader() *xlsxCalcChain {
	if f.CalcChain == nil {
		var c xlsxCalcChain
		_ = xml.Unmarshal(namespaceStrictToTransitional(f.readXML("xl/calcChain.xml")), &c)
		f.CalcChain = &c
	}
	return f.CalcChain
}
1346855
func (gr *GoReq) SetHeader(param string, value string) *GoReq {
	gr.Header[param] = value
	return gr
}
1183179
func newSparseFileReader(rfr numBytesReader, sp []sparseEntry, total int64) (*sparseFileReader, error) {
	if total < 0 {
		return nil, ErrHeader // Total size cannot be negative
	}

	// Validate all sparse entries. These are the same checks as performed by
	// the BSD tar utility.
	for i, s := range sp {
		switch {
		case s.offset < 0 || s.numBytes < 0:
			return nil, ErrHeader // Negative values are never okay
		case s.offset > math.MaxInt64-s.numBytes:
			return nil, ErrHeader // Integer overflow with large length
		case s.offset+s.numBytes > total:
			return nil, ErrHeader // Region extends beyond the "real" size
		case i > 0 && sp[i-1].offset+sp[i-1].numBytes > s.offset:
			return nil, ErrHeader // Regions can't overlap and must be in order
		}
	}
	return &sparseFileReader{rfr: rfr, sp: sp, total: total}, nil
}
825806
func ParseDenseARFFBuildInstancesFromReader(r io.Reader, attrs []Attribute, u UpdatableDataGrid) (err error) {
	var rowCounter int

	defer func() {
		if r := recover(); r != nil {
			if _, ok := r.(runtime.Error); ok {
				panic(err)
			}
			err = fmt.Errorf("Error at line %d (error %s)", rowCounter, r.(error))
		}
	}()

	scanner := bufio.NewScanner(r)
	reading := false
	specs := ResolveAttributes(u, attrs)
	for scanner.Scan() {
		line := scanner.Text()
		if strings.HasPrefix(line, "%") {
			continue
		}
		if reading {
			buf := bytes.NewBuffer([]byte(line))
			reader := csv.NewReader(buf)
			for {
				r, err := reader.Read()
				if err == io.EOF {
					break
				} else if err != nil {
					return err
				}
				for i, v := range r {
					v = strings.TrimSpace(v)
					if a, ok := specs[i].attr.(*CategoricalAttribute); ok {
						if val := a.GetSysVal(v); val == nil {
							panic(fmt.Errorf("Unexpected class on line '%s'", line))
						}
					}
					u.Set(specs[i], rowCounter, specs[i].attr.GetSysValFromString(v))
				}
				rowCounter++
			}
		} else {
			line = strings.ToLower(line)
			line = strings.TrimSpace(line)
			if line == "@data" {
				reading = true
			}
		}
	}

	return nil
}
1291852
func calcDigest(inputs map[string][]byte) string {
	keys := make([]string, 0, len(inputs))
	for k := range inputs {
		keys = append(keys, k)
	}
	sort.Strings(keys)
	h := sha1.New()
	for _, k := range keys {
		v := inputs[k]
		fmt.Fprintf(h, "%s\n%d\n", k, len(v))
		h.Write(v)
	}
	blob := h.Sum(nil)
	return hex.EncodeToString(blob[:])
}
146178
func xmlDecoder(body io.Reader, v interface{}) error {
	d := xml.NewDecoder(body)
	return d.Decode(v)
}
669093
func readHeader(reader io.Reader, sectorSize uint64) (res Header, err error) {
	read := func(data interface{}) {
		if err == nil {
			err = binary.Read(reader, binary.LittleEndian, data)
		}
	}

	read(&res.Signature)
	read(&res.Revision)
	read(&res.Size)
	read(&res.CRC)
	read(&res.Reserved)
	read(&res.HeaderStartLBA)
	read(&res.HeaderCopyStartLBA)
	read(&res.FirstUsableLBA)
	read(&res.LastUsableLBA)
	read(&res.DiskGUID)
	read(&res.PartitionsTableStartLBA)
	read(&res.PartitionsArrLen)
	read(&res.PartitionEntrySize)
	read(&res.PartitionsCRC)
	if err != nil {
		return
	}

	if string(res.Signature[:]) != "EFI PART" {
		return res, fmt.Errorf("Bad GPT signature")
	}
	trailingBytes := make([]byte, sectorSize-uint64(standardHeaderSize))
	reader.Read(trailingBytes)
	res.TrailingBytes = trailingBytes

	if res.calcCRC() != res.CRC {
		return res, fmt.Errorf("BAD GPT Header CRC")
	}

	return
}
179732
func (s *storageImpl) GetReader(c context.Context, ref *api.ObjectRef) (r gs.Reader, err error) {
	defer func() { err = grpcutil.GRPCifyAndLogErr(c, err) }()

	if err = common.ValidateObjectRef(ref, common.KnownHash); err != nil {
		return nil, errors.Annotate(err, "bad ref").Err()
	}

	cfg, err := s.settings(c)
	if err != nil {
		return nil, err
	}

	r, err = s.getGS(c).Reader(c, cfg.ObjectPath(ref), 0)
	if err != nil {
		ann := errors.Annotate(err, "can't read the object")
		if gs.StatusCode(err) == http.StatusNotFound {
			ann.Tag(grpcutil.NotFoundTag)
		}
		return nil, ann.Err()
	}
	return r, nil
}
139994
func (t *TTFParser) ParseHead(fd *bytes.Reader) error {

	//fmt.Printf("\nParseHead\n")
	err := t.Seek(fd, "head")
	if err != nil {
		return err
	}

	err = t.Skip(fd, 3*4) // version, fontRevision, checkSumAdjustment
	if err != nil {
		return err
	}
	magicNumber, err := t.ReadULong(fd)
	if err != nil {
		return err
	}

	//fmt.Printf("\nmagicNumber = %d\n", magicNumber)
	if magicNumber != 0x5F0F3CF5 {
		return ERROR_INCORRECT_MAGIC_NUMBER
	}

	err = t.Skip(fd, 2)
	if err != nil {
		return err
	}

	t.unitsPerEm, err = t.ReadUShort(fd)
	if err != nil {
		return err
	}

	err = t.Skip(fd, 2*8) // created, modified
	if err != nil {
		return err
	}

	t.xMin, err = t.ReadShort(fd)
	if err != nil {
		return err
	}

	t.yMin, err = t.ReadShort(fd)
	if err != nil {
		return err
	}

	t.xMax, err = t.ReadShort(fd)
	if err != nil {
		return err
	}

	t.yMax, err = t.ReadShort(fd)
	if err != nil {
		return err
	}

	err = t.Skip(fd, 2*3) //skip macStyle,lowestRecPPEM,fontDirectionHint
	if err != nil {
		return err
	}

	t.indexToLocFormat, err = t.ReadShort(fd)
	if err != nil {
		return err
	}

	return nil
}
731842
func ParseCSVBuildInstancesFromReader(r io.ReadSeeker, attrs []Attribute, hasHeader bool, u UpdatableDataGrid) (err error) {
	var rowCounter int

	defer func() {
		if r := recover(); r != nil {
			if _, ok := r.(runtime.Error); ok {
				panic(err)
			}
			err = fmt.Errorf("error at line %d (error %s)", rowCounter, r.(error))
		}
	}()

	specs := ResolveAttributes(u, attrs)

	r.Seek(0, 0)
	reader := csv.NewReader(r)

	for {
		record, err := reader.Read()
		if err == io.EOF {
			break
		} else if err != nil {
			return err
		}
		if rowCounter == 0 {
			if hasHeader {
				hasHeader = false
				continue
			}
		}
		for i, v := range record {
			u.Set(specs[i], rowCounter, specs[i].attr.GetSysValFromString(strings.TrimSpace(v)))
		}
		rowCounter++
	}

	return nil
}
1008098
func ParseReader(in io.Reader, ch chan<- *dto.MetricFamily) error {
	defer close(ch)
	// We could do further content-type checks here, but the
	// fallback for now will anyway be the text format
	// version 0.0.4, so just go for it and see if it works.
	var parser expfmt.TextParser
	metricFamilies, err := parser.TextToMetricFamilies(in)
	if err != nil {
		return fmt.Errorf("reading text format failed: %v", err)
	}
	for _, mf := range metricFamilies {
		ch <- mf
	}
	return nil
}
788397
func (q *QueryFeedback) CalcErrorRate() float64 {
	expected := float64(q.Expected)
	if q.actual == 0 {
		if expected == 0 {
			return 0
		}
		return 1
	}
	return math.Abs(expected-float64(q.actual)) / float64(q.actual)
}
380124
func (r *Reader) readRef() interface{} {
	if r.Simple {
		panic(errors.New("reference unserialization can't support in simple mode"))
	}
	return readRef(r, r.readInt())
}
799632
func readDecorator(component string) (out []byte, err error) {
	decoratorName := "deis-" + component + ".service.decorator"
	var decoratorFile string

	// look in $DEISCTL_UNITS env var, then the local and global root paths
	for _, p := range decoratorPaths {
		filename := path.Join(p, decoratorName)
		if _, err := os.Stat(filename); err == nil {
			decoratorFile = filename
			break
		}
	}

	if decoratorFile == "" {
		return
	}
	out, err = ioutil.ReadFile(decoratorFile)
	return
}
857054
func ReadFunc(r io.Reader, rm ReaderMaker, fn func(r io.ReaderFrom)) (int64, error) {
	var n int64

	for {
		reader, err := rm.MakeReader()
		if err != nil {
			return n, err
		}

		nn, err := reader.ReadFrom(r)
		n += nn

		if err != nil {
			return n, SkipEOF(err)
		}

		fn(reader)
	}
}
28920
func (d *Data) lookupReader(scheme string) (func(*Source, ...string) ([]byte, error), error) {
	if d.sourceReaders == nil {
		d.registerReaders()
	}
	r, ok := d.sourceReaders[scheme]
	if !ok {
		return nil, errors.Errorf("scheme %s not registered", scheme)
	}
	return r, nil
}
307225
func (h *blockHeaderStore) readHeader(height uint32) (wire.BlockHeader, error) {
	var header wire.BlockHeader

	// Each header is 80 bytes, so using this information, we'll seek a
	// distance to cover that height based on the size of block headers.
	seekDistance := uint64(height) * 80

	// With the distance calculated, we'll raw a raw header start from that
	// offset.
	rawHeader, err := h.readRaw(seekDistance)
	if err != nil {
		return header, err
	}
	headerReader := bytes.NewReader(rawHeader)

	// Finally, decode the raw bytes into a proper bitcoin header.
	if err := header.Deserialize(headerReader); err != nil {
		return header, err
	}

	return header, nil
}