// ReadInfo reads the underlying reader finds the data it needs.
// This method is safe to call multiple times.
428056
func (d *Decoder) ReadInfo() error {
	if d == nil || d.SampleRate > 0 {
		return nil
	}
	if d.err = d.readHeaders(); d.err != nil {
		d.err = fmt.Errorf("failed to read header - %v", d.err)
		return d.err
	}

	var chk *chunk.Reader
	var err error
	for err == nil {
		chk, err = d.NextChunk()
		if err != nil {
			break
		}
		switch chk.ID {
		case AudioDataChunkID:
			d.AudioDataSize = int64(chk.Size)
			// TODO:
			// editCount uint32
			// The modification status of the data section. You should initially set this field to 0, and should increment it each time the audio data in the file is modified.
			// the rest of the data is the actual audio data.
		case InfoStringsChunkID:
			strChunk := &stringsChunk{stringID: map[string]string{}}
			if err = chk.ReadBE(&strChunk.numEntries); err != nil {
				return fmt.Errorf("failed to read the info strings chunk data - %v", err)
			}
			if strChunk.numEntries > 0 {
				for i := uint32(0); i < strChunk.numEntries; i++ {
					// read key(max 32 bytes) + data (max 1024) both null delimited.
					// TODO: this is terrible for performance reasons. Read the entire chunk in memory for that.
					key := []byte{}
					var b byte
					msg := []byte{}
					var msgB byte
					for j := 0; j < 32; j++ {
						b, err = chk.ReadByte()
						if err != nil {
							break
						}
						// end of key?
						if b == 0x0 {
							for k := 0; k < 1024; k++ {
								msgB, err = chk.ReadByte()
								if err != nil {
									break
								}
								// message terminated
								if msgB == 0x0 {
									break
								}
								msg = append(msg, msgB)
							}
							break
						}
						key = append(key, b)
					}
					if len(key) > 0 {
						strChunk.stringID[string(key)] = string(msg)
					}
				}

				for k, v := range strChunk.stringID {
					fmt.Printf("%s -> %s\n", k, v)
				}
			}

			// kuki
			// The Magic Cookie chunk contains supplementary (“magic cookie”) data required by certain audio data formats, such as MPEG-4 AAC, for decoding of the audio data. If the audio data format contained in a CAF file requires magic cookie data, the file must have this chunk.
			// https://developer.apple.com/library/content/documentation/MusicAudio/Reference/CAFSpec/CAF_spec/CAF_spec.html#//apple_ref/doc/uid/TP40001862-CH210-BCGFCCFA

			// strg
			// The optional Strings chunk contains any number of textual
			// strings, along with an index for accessing them. These strings serve
			// as labels for other chunks, such as Marker or Region chunks.

			// free
			// The optional Free chunk is for reserving space, or providing
			// padding, in a CAF file. The contents of the Free chunk data section
			// have no significance and should be ignored.

			// info
			// You can use the optional Information chunk to contain any number
			// of human-readable text strings. Each string is accessed through a
			// standard or application-defined key. You should consider information
			// in this chunk to be secondary when the same information appears in
			// other chunks. For example, both the Information chunk and the MIDI
			// chunk (MIDI Chunk) may specify key signature and tempo. In that case,
			// the MIDI chunk values overrides the values in the Information chunk.

			// uuid
			//
			// You can define your own chunk type to extend the CAF file
			// specification. For this purpose, this specification includes the
			// User-Defined chunk type, which you can use to provide a unique
			// universal identifier for your custom chunk. When parsing a CAF file,
			// you should ignore any chunk with a UUID that you do not recognize.

			// ovvw
			//
			// You can use the optional Overview chunk to hold sample descriptions
			// that you can use to draw a graphical view of the audio data in a CAF
			// file. A CAF file can include multiple Overview chunks to represent
			// the audio at multiple graphical resolutions.

			// peak
			//
			// You can use the optional Peak chunk to describe the peak amplitude
			// present in each channel of a CAF file and to indicate in which frame
			// the peak occurs for each channel.
		}
		chk.Done()
	}

	if d.err == nil && d.err != nil {
		d.err = err
	}
	return d.Err()
}
1253239
func Load(r io.Reader) (*MetaInfo, error) {
	var mi MetaInfo
	d := bencode.NewDecoder(r)
	err := d.Decode(&mi)
	if err != nil {
		return nil, err
	}
	return &mi, nil
}
1084885
func (br *bufReader) Read(p []byte) (n int, err error) {
	if br.err != nil {
		return 0, br.err
	}
	return br.buf.Read(p)
}
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())
}
296360
func ReadInfoForRef(basefile string, ref string) (interface{}, error) {
	initializeInfoCache()
	if infoCacheEnable {
		info, ok := infoCache[ref]
		if ok {
			if verboseReader {
				log.Printf("Cache hit for ref %s#%s", basefile, ref)
			}
			return info, nil
		}
		if verboseReader {
			log.Printf("Reading info for ref %s#%s", basefile, ref)
		}
	}
	count = count + 1
	basedir, _ := filepath.Split(basefile)
	parts := strings.Split(ref, "#")
	var filename string
	if parts[0] != "" {
		filename = basedir + parts[0]
	} else {
		filename = basefile
	}
	bytes, err := ReadBytesForFile(filename)
	if err != nil {
		return nil, err
	}
	info, err := ReadInfoFromBytes(filename, bytes)
	if err != nil {
		log.Printf("File error: %v\n", err)
	} else {
		if len(parts) > 1 {
			path := strings.Split(parts[1], "/")
			for i, key := range path {
				if i > 0 {
					m, ok := info.(yaml.MapSlice)
					if ok {
						found := false
						for _, section := range m {
							if section.Key == key {
								info = section.Value
								found = true
							}
						}
						if !found {
							infoCache[ref] = nil
							return nil, NewError(nil, fmt.Sprintf("could not resolve %s", ref))
						}
					}
				}
			}
		}
	}
	if infoCacheEnable {
		infoCache[ref] = info
	}
	return info, nil
}
1186852
func (r *Reader) Read(buffer []byte) (n int, err error) {
	if r.reader == nil {
		n = len(buffer)
	} else {
		n, err = r.reader.Read(buffer)
	}

	r.count += int64(n)
	if r.onRead != nil {
		r.onRead(r.count)
	}
	return
}
295013
func (g *Group) readGroupInfo() GroupInfo {
	groupDir := filepath.Dir(g.Head.Path)
	headBase := filepath.Base(g.Head.Path)
	var minIndex, maxIndex int = -1, -1
	var totalSize, headSize int64 = 0, 0

	dir, err := os.Open(groupDir)
	if err != nil {
		panic(err)
	}
	defer dir.Close()
	fiz, err := dir.Readdir(0)
	if err != nil {
		panic(err)
	}

	// For each file in the directory, filter by pattern
	for _, fileInfo := range fiz {
		if fileInfo.Name() == headBase {
			fileSize := fileInfo.Size()
			totalSize += fileSize
			headSize = fileSize
			continue
		} else if strings.HasPrefix(fileInfo.Name(), headBase) {
			fileSize := fileInfo.Size()
			totalSize += fileSize
			indexedFilePattern := regexp.MustCompile(`^.+\.([0-9]{3,})$`)
			submatch := indexedFilePattern.FindSubmatch([]byte(fileInfo.Name()))
			if len(submatch) != 0 {
				// Matches
				fileIndex, err := strconv.Atoi(string(submatch[1]))
				if err != nil {
					panic(err)
				}
				if maxIndex < fileIndex {
					maxIndex = fileIndex
				}
				if minIndex == -1 || fileIndex < minIndex {
					minIndex = fileIndex
				}
			}
		}
	}

	// Now account for the head.
	if minIndex == -1 {
		// If there were no numbered files,
		// then the head is index 0.
		minIndex, maxIndex = 0, 0
	} else {
		// Otherwise, the head file is 1 greater
		maxIndex++
	}
	return GroupInfo{minIndex, maxIndex, totalSize, headSize}
}
501459
func (r *Reader) Read(b []byte) (int, error) {
	// if we have data in the buffer, just
	// return that.
	if r.buffered() != 0 {
		x := copy(b, r.data[r.n:])
		r.n += x
		return x, nil
	}
	var n int
	// we have no buffered data; determine
	// whether or not to buffer or call
	// the underlying reader directly
	if len(b) >= cap(r.data) {
		n, r.state = r.r.Read(b)
	} else {
		r.more()
		n = copy(b, r.data)
		r.n = n
	}
	if n == 0 {
		return 0, r.err()
	}
	return n, nil
}
643184
func (r *translateFileReader) Read(p []byte) (n int, err error) {
	for {
		// Obtain notification channel before we check for new data.
		notify := r.store.WriteNotify()

		// Exit if we can read one or more valid entries or we receive an error.
		if n, err = r.read(p); n > 0 || err != nil {
			return n, err
		}

		// Wait for new data or close.
		select {
		case <-r.ctx.Done():
			return 0, r.ctx.Err()
		case <-r.closing:
			return 0, ErrTranslateStoreReaderClosed
		case <-r.store.Closing():
			return 0, ErrTranslateStoreClosed
		case <-notify:
			continue
		}
	}
}
925785
func (c *Client) GetInfo() (*Info, error) {
	r := c.NewRequest("GET", "/v2/info")
	resp, err := c.DoRequest(r)
	if err != nil {
		return nil, errors.Wrap(err, "Error requesting info")
	}
	defer resp.Body.Close()
	var i Info
	err = json.NewDecoder(resp.Body).Decode(&i)
	if err != nil {
		return nil, errors.Wrap(err, "Error unmarshalling info")
	}
	return &i, nil
}
232099
func (rd *Reader) Read(b []byte) (n int, err error) {
	if rd.nb == 0 {
		return 0, io.EOF
	}
	if int64(len(b)) > rd.nb {
		b = b[0:rd.nb]
	}
	n, err = rd.r.Read(b)
	rd.nb -= int64(n)

	return
}
387425
func (l *localFileInfo) ReadDir() ([]FileInfo, error) {
	f, err := os.Open(l.filePath)
	if err != nil {
		return nil, trace.Wrap(err)
	}

	fis, err := f.Readdir(0)
	if err != nil {
		return nil, trace.Wrap(err)
	}

	infos := make([]FileInfo, len(fis))
	for i := range fis {
		fi := fis[i]
		info, err := makeFileInfo(filepath.Join(l.GetPath(), fi.Name()))
		if err != nil {
			return nil, trace.Wrap(err)
		}
		infos[i] = info
	}

	return infos, nil
}
127298
func (i *Int32) ReadFrom(r Reader, l int) error {
	if l != UNKNOWN_LEN && l != 4 {
		return errorsp.WithStacksAndMessage(ErrBadFormat, "l = %d", l)
	}

	var arr [4]byte
	if _, err := io.ReadFull(r, arr[:]); err != nil {
		return errorsp.WithStacks(err)
	}
	*i = Int32(arr[0]) | Int32(arr[1])<<8 | Int32(arr[2])<<16 |
		Int32(arr[3])<<24
	return nil
}
603281
func (s *SelectResults) Read(b []byte) (n int, err error) {
	return s.pipeReader.Read(b)
}
540891
func readMiscInfo(mdmp *Minidump, buf *minidumpBuf) {
	buf.u32() // size of info
	buf.u32() // flags1

	mdmp.Pid = buf.u32() // process_id
	// there are more fields here, but we don't care about them
}
1349476
func ReadType(d *dwarf.Data, off dwarf.Offset, typeCache map[dwarf.Offset]Type) (Type, error) {
	return readType(d, "info", d.Reader(), off, typeCache)
}
154801
func (a *TrackingReader) Read(b []byte) (int, error) {
	a.ctx.UpdateClientActivity()
	return a.r.Read(b)
}