// themeReader provides a function to get the pointer to the xl/theme/theme1.xml
// structure after deserialization.
160889
func (f *File) themeReader() *xlsxTheme {
	var theme xlsxTheme
	_ = xml.Unmarshal(namespaceStrictToTransitional(f.readXML("xl/theme/theme1.xml")), &theme)
	return &theme
}
1251167
func xmlDecoder(body io.Reader, v interface{}, size int64) error {
	var lbody io.Reader
	if size > 0 {
		lbody = io.LimitReader(body, size)
	} else {
		lbody = body
	}
	d := xml.NewDecoder(lbody)
	// Ignore any encoding set in the XML body
	d.CharsetReader = nopCharsetConverter
	return d.Decode(v)
}
1213943
func runeReader(r io.Reader) io.RuneReader {
	if rr, ok := r.(io.RuneReader); ok {
		return rr
	}
	return bufio.NewReader(r)
}
250336
func ThemeColor(baseColor string, tint float64) string {
	if tint == 0 {
		return "FF" + baseColor
	}
	r, _ := strconv.ParseInt(baseColor[0:2], 16, 64)
	g, _ := strconv.ParseInt(baseColor[2:4], 16, 64)
	b, _ := strconv.ParseInt(baseColor[4:6], 16, 64)
	h, s, l := RGBToHSL(uint8(r), uint8(g), uint8(b))
	if tint < 0 {
		l *= (1 + tint)
	} else {
		l = l*(1-tint) + (1 - (1 - tint))
	}
	br, bg, bb := HSLToRGB(h, s, l)
	return fmt.Sprintf("FF%02X%02X%02X", br, bg, bb)
}
744492
func (f *FileStorage) GetReader() (io.ReadCloser, error) {
	newFile, err := os.Open(f.file.Name())
	if err != nil {
		return nil, err
	}
	return &FileReader{
		content:      newFile,
		subscription: f.subscription.NewSubscriber(),
		unsubscribe:  f.subscription.RemoveSubscriber,
	}, nil
}
704000
func FromReader(reader io.Reader) Source {
	m := make(map[string]string)

	s := bufio.NewScanner(bufio.NewReader(reader))
	for s.Scan() {
		l := s.Text()
		p := keyValueRE.FindStringSubmatch(l)
		if p == nil {
			continue
		}
		m[strings.ToLower(p[1])] = p[2]
	}
	if err := s.Err(); err != nil {
		return Err(err)
	}
	return FromMap(m)
}
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
}
509310
func (f *File) workSheetRelsReader(path string) *xlsxWorkbookRels {
	if f.WorkSheetRels[path] == nil {
		_, ok := f.XLSX[path]
		if ok {
			c := xlsxWorkbookRels{}
			_ = xml.Unmarshal(namespaceStrictToTransitional(f.readXML(path)), &c)
			f.WorkSheetRels[path] = &c
		}
	}
	return f.WorkSheetRels[path]
}
302213
func DeserializeInstancesFromTarReader(tr *FunctionalTarReader, prefix string) (ret *DenseInstances, err error) {

	p := func(n string) string {
		return fmt.Sprintf("%s%s", prefix, n)
	}

	// Retrieve the MANIFEST and verify
	manifestBytes, err := tr.GetNamedFile(p("MANIFEST"))
	if err != nil {
		return nil, err
	}
	if !reflect.DeepEqual(manifestBytes, []byte(SerializationFormatVersion)) {
		return nil, fmt.Errorf("Unsupported MANIFEST: %s", string(manifestBytes))
	}

	// Get the size
	sizeBytes, err := tr.GetNamedFile(p("DIMS"))
	if err != nil {
		return nil, WrapError(fmt.Errorf("Unable to read DIMS: %v", err))
	}
	if len(sizeBytes) < 16 {
		return nil, WrapError(fmt.Errorf("DIMS: must be 16 bytes"))
	}
	attrCount := int(UnpackBytesToU64(sizeBytes[0:8]))
	rowCount := int(UnpackBytesToU64(sizeBytes[8:]))

	// Unmarshal the Attributes
	attrBytes, err := tr.GetNamedFile(p("CATTRS"))
	if err != nil {
		return nil, DescribeError("Unable to read CATTRS", err)
	}
	cAttrs, err := DeserializeAttributes(attrBytes)
	if err != nil {
		return nil, DescribeError("Class Attribute deserialization error", err)
	}
	attrBytes, err = tr.GetNamedFile(p("ATTRS"))
	if err != nil {
		return nil, DescribeError("Unable to read ATTRS", err)
	}
	normalAttrs, err := DeserializeAttributes(attrBytes)
	if err != nil {
		return nil, DescribeError("Unable to deserialize normal attributes", err)
	}

	// Create the return instances
	ret = NewDenseInstances()

	// Normal Attributes first, class Attributes on the end
	allAttributes := make([]Attribute, attrCount)
	for i, v := range normalAttrs {
		ret.AddAttribute(v)
		allAttributes[i] = v
	}
	for i, v := range cAttrs {
		ret.AddAttribute(v)
		err = ret.AddClassAttribute(v)
		if err != nil {
			return nil, DescribeError(fmt.Sprintf("Could not set Attribute '%s' as a class Attribute", v), err)
		}
		allAttributes[i+len(normalAttrs)] = v
	}
	// Allocate memory
	err = ret.Extend(int(rowCount))
	if err != nil {
		return nil, WrapError(fmt.Errorf("Could not allocate memory"))
	}

	// Seek through the TAR file until we get to the DATA section
	reader := tr.Regenerate()
	for {
		hdr, err := reader.Next()
		if err == io.EOF {
			return nil, WrapError(fmt.Errorf("DATA section missing!"))
		} else if err != nil {
			return nil, WrapError(fmt.Errorf("Error seeking to DATA section: %s", err))
		}
		if hdr.Name == p("DATA") {
			break
		}
	}

	// Resolve AttributeSpecs
	specs := ResolveAttributes(ret, allAttributes)

	// Finally, read the values out of the data section
	for i := 0; i < rowCount; i++ {
		for j, s := range specs {
			r := ret.Get(s, i)
			n, err := reader.Read(r)
			if n != len(r) {
				return nil, WrapError(fmt.Errorf("Expected %d bytes (read %d) on row %d", len(r), n, i))
			}
			ret.Set(s, i, r)
			if err != nil {
				if i == rowCount-1 && j == len(specs)-1 && err == io.EOF {
					break
				}
				return nil, WrapError(fmt.Errorf("Read error in data section (at row %d from %d, attr %d from %d): %s", i, rowCount, j, len(specs), err))
			}
		}
	}

	return ret, nil
}
953510
func NewReader(base string) *Reader {
	stats, _ := os.Stat(base)
	if stats != nil {
		if stats.IsDir() {
			return NewDirReader(base)
		}
		return NewYAMLReader(base)
	}
	return NewEnvReader()
}
625100
func indexer(node *treeNode, index int) *treeNode {

	if index < node.leftSize() {
		return indexer(node.left, index)
	} else if index == node.leftSize() {
		return node
	} else if node.right != nil {
		return indexer(node.right, index-(node.leftSize()+1))
	}
	return nil
}
36376
func (excel *Excel) NewReader(res *exchange.Resource, context *qor.Context) (exchange.Rows, error) {
	var rows = Rows{Excel: excel, Resource: res}

	readCloser, err := excel.getReader()
	if err == nil {
		defer readCloser.Close()
		var (
			reader, err = excelize.OpenReader(readCloser)
			sheetName   = excel.config.SheetName
		)

		if sheetName == "" {
			activeSheet := reader.GetActiveSheetIndex()
			if activeSheet == 0 && reader.SheetCount > 0 {
				activeSheet = 1
			}
			sheetName = reader.GetSheetName(activeSheet)
		}

		if err != nil {
			return nil, err
		}

		rows.records, err = reader.GetRows(sheetName)
		if err != nil {
			return nil, err
		}

		for i, r := range rows.records {
			for j, v := range r {
				rows.records[i][j] = strings.TrimSpace(v)
			}
		}

		rows.total = len(rows.records) - 1
		if res.Config.WithoutHeader {
			rows.total++
		}
	}

	return &rows, err
}
1236904
func SumReader(algo string, r io.Reader) ([]byte, error) {
	h, err := New(algo)
	if err != nil {
		return nil, err
	}

	_, err = io.Copy(h, r)
	if err != nil {
		return nil, err
	}

	return h.Sum(nil), nil
}
1092657
func NewReadCloseResetter(ctx context.Context, g *libkb.GlobalContext,
	p string) (ReadCloseResetter, error) {
	if isKbfsPath(p) {
		return NewKbfsReadCloseResetter(ctx, g, p)
	}
	return NewFileReadCloseResetter(p)
}
703496
func (rs *Ruleset) LoadReader(r io.Reader) error {
	m := map[string]string{}
	err := json.NewDecoder(r).Decode(&m)
	if err != nil {
		return fmt.Errorf("could not decode inflection JSON from reader: %s", err)
	}
	for s, p := range m {
		defaultRuleset.AddIrregular(s, p)
	}
	return nil
}
571541
func (c Checker) WrapReader(reader io.Reader) io.Reader {
	hashingReader := io.TeeReader(reader, c.ChecksumWriter)
	return io.TeeReader(hashingReader, c.SizeTracker)
}
24594
func (ctx *Context) ScanReader(r io.Reader) BasicScanner {
	return ctx.SetScanner(&ScanReader{sr: bufio.NewScanner(r)})
}