// workSheetRelsReader provides a function to get the pointer to the structure
// after deserialization of xl/worksheets/_rels/sheet%d.xml.rels.
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]
}
264982
func (f *File) workSheetRelsWriter() {
	for p, r := range f.WorkSheetRels {
		if r != nil {
			v, _ := xml.Marshal(r)
			f.saveFileList(p, v)
		}
	}
}
833468
func (f *File) deleteSheetFromWorkbookRels(rID string) string {
	content := f.workbookRelsReader()
	for k, v := range content.Relationships {
		if v.ID == rID {
			content.Relationships = append(content.Relationships[:k], content.Relationships[k+1:]...)
			return v.Target
		}
	}
	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
}
786042
func LoadReader(r io.Reader) error {
	env, err := Read(r)
	if err != nil {
		return err
	}
	LoadMap(env, false)
	return nil
}
242068
func (f *File) GetSheetName(index int) string {
	content := f.workbookReader()
	rels := f.workbookRelsReader()
	for _, rel := range rels.Relationships {
		rID, _ := strconv.Atoi(strings.TrimSuffix(strings.TrimPrefix(rel.Target, "worksheets/sheet"), ".xml"))
		if rID == index {
			for _, v := range content.Sheets.Sheet {
				if v.ID == rel.ID {
					return v.Name
				}
			}
		}
	}
	return ""
}
1199351
func (h *TermsHashPerFieldImpl) initReader(reader *ByteSliceReader, termId, stream int) {
	assert(stream < h.streamCount)
	intStart := h.postingsArray.intStarts[termId]
	ints := h.intPool.Buffers[intStart>>util.INT_BLOCK_SHIFT]
	upto := intStart & util.INT_BLOCK_MASK
	reader.init(h.bytePool,
		h.postingsArray.byteStarts[termId]+stream*util.FIRST_LEVEL_SIZE,
		ints[upto+stream])
}
1126026
func (t *TSMReader) Iterator(key []byte) TSMIterator {
	return t.index.Iterator(key)
}
774932
func (r *Reader) InitReader(b []byte) {
	r.s = b
	r.i = 0
}
1334719
func ParseCSVToTemplatedInstancesFromReader(r io.ReadSeeker, hasHeaders bool, template *DenseInstances) (instances *DenseInstances, err error) {
	// Read the number of rows in the file
	rowCount, err := ParseCSVGetRowsFromReader(r)
	if err != nil {
		return nil, err
	}

	if hasHeaders {
		rowCount--
	}

	// Read the row headers
	attrs := ParseCSVGetAttributesFromReader(r, hasHeaders)
	templateAttrs := template.AllAttributes()
	ParseMatchAttributes(attrs, templateAttrs)

	// Allocate the Instances to return
	instances = CopyDenseInstances(template, templateAttrs)
	instances.Extend(rowCount)

	err = ParseCSVBuildInstancesFromReader(r, attrs, hasHeaders, instances)
	if err != nil {
		return nil, err
	}

	for _, a := range template.AllClassAttributes() {
		err = instances.AddClassAttribute(a)
		if err != nil {
			return nil, err
		}
	}

	return instances, nil
}
252085
func NewResultReader(qs QuadStore, it Iterator) quad.ReadSkipCloser {
	if it == nil {
		it = qs.QuadsAllIterator()
	}
	return &quadReader{qs: qs, it: it}
}
1092657
func NewReadCloseResetter(ctx context.Context, g *libkb.GlobalContext,
	p string) (ReadCloseResetter, error) {
	if isKbfsPath(p) {
		return NewKbfsReadCloseResetter(ctx, g, p)
	}
	return NewFileReadCloseResetter(p)
}
403870
func getWorksheetFromSheet(sheet xlsxSheet, worksheets map[string]*zip.File, sheetXMLMap map[string]string, rowLimit int) (*xlsxWorksheet, error) {
	var r io.Reader
	var decoder *xml.Decoder
	var worksheet *xlsxWorksheet
	var err error
	worksheet = new(xlsxWorksheet)

	f := worksheetFileForSheet(sheet, worksheets, sheetXMLMap)
	if f == nil {
		return nil, fmt.Errorf("Unable to find sheet '%s'", sheet)
	}
	if rc, err := f.Open(); err != nil {
		return nil, err
	} else {
		defer rc.Close()
		r = rc
	}

	if rowLimit != NoRowLimit {
		r, err = truncateSheetXML(r, rowLimit)
		if err != nil {
			return nil, err
		}
	}

	decoder = xml.NewDecoder(r)
	err = decoder.Decode(worksheet)
	if err != nil {
		return nil, err
	}
	return worksheet, nil
}
97986
func (f *File) workSheetWriter() {
	for p, sheet := range f.Sheet {
		if sheet != nil {
			for k, v := range sheet.SheetData.Row {
				f.Sheet[p].SheetData.Row[k].C = trimCell(v.C)
			}
			output, _ := xml.Marshal(sheet)
			f.saveFileList(p, replaceRelationshipsBytes(replaceWorkSheetsRelationshipsNameSpaceBytes(output)))
			ok := f.checked[p]
			if ok {
				f.checked[p] = false
			}
		}
	}
}
1073862
func StorageReader(storage StorageAPI, volume, path string, offset int64) io.Reader {
	return &storageReader{storage, volume, path, offset}
}
782129
func ReadZipReader(r *zip.Reader) (map[string][]byte, int, error) {
	fileList := make(map[string][]byte)
	worksheets := 0
	for _, v := range r.File {
		fileList[v.Name] = readFile(v)
		if len(v.Name) > 18 {
			if v.Name[0:19] == "xl/worksheets/sheet" {
				worksheets++
			}
		}
	}
	return fileList, worksheets, nil
}
249836
func (r *Row) ReadStruct(ptr interface{}) error {
	if ptr == nil {
		return errNilInterface
	}
	//check if the type implements XLSXUnmarshaler. If so,
	//just let it do the work.
	unmarshaller, ok := ptr.(XLSXUnmarshaler)
	if ok {
		return unmarshaller.Unmarshal(r)
	}
	v := reflect.ValueOf(ptr)
	if v.Kind() != reflect.Ptr {
		return errNotStructPointer
	}
	v = v.Elem()
	if v.Kind() != reflect.Struct {
		return errNotStructPointer
	}
	n := v.NumField()
	for i := 0; i < n; i++ {
		field := v.Type().Field(i)
		idx := field.Tag.Get("xlsx")
		//do a recursive check for the field if it is a struct or a pointer
		//even if it doesn't have a tag
		//ignore if it has a - or empty tag
		isTime := false
		switch {
		case idx == "-":
			continue
		case field.Type.Kind() == reflect.Ptr || field.Type.Kind() == reflect.Struct:
			var structPtr interface{}
			if !v.Field(i).CanSet() {
				continue
			}
			if field.Type.Kind() == reflect.Struct {
				structPtr = v.Field(i).Addr().Interface()
			} else {
				structPtr = v.Field(i).Interface()
			}
			//check if the container is a time.Time
			_, isTime = structPtr.(*time.Time)
			if isTime {
				break
			}
			err := r.ReadStruct(structPtr)
			if err != nil {
				return err
			}
			continue
		case len(idx) == 0:
			continue
		}
		pos, err := strconv.Atoi(idx)
		if err != nil {
			return errInvalidTag
		}

		//check if desired position is not out of bounds
		if pos > len(r.Cells)-1 {
			continue
		}
		cell := r.Cells[pos]
		fieldV := v.Field(i)
		//continue if the field is not settable
		if !fieldV.CanSet() {
			continue
		}
		if isTime {
			t, err := cell.GetTime(false)
			if err != nil {
				return err
			}
			if field.Type.Kind() == reflect.Ptr {
				fieldV.Set(reflect.ValueOf(&t))
			} else {
				fieldV.Set(reflect.ValueOf(t))
			}
			continue
		}
		switch field.Type.Kind() {
		case reflect.String:
			value, err := cell.FormattedValue()
			if err != nil {
				return err
			}
			fieldV.SetString(value)
		case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
			value, err := cell.Int64()
			if err != nil {
				return err
			}
			fieldV.SetInt(value)
		case reflect.Float64:
			value, err := cell.Float()
			if err != nil {
				return err
			}
			fieldV.SetFloat(value)
		case reflect.Bool:
			value := cell.Bool()
			fieldV.SetBool(value)
		}
	}
	value := v.Interface()
	ptr = &value
	return nil
}