func decIndex(s *xzDec, b *xzBuf) xzRet {
	var ret xzRet
	for {
		ret = decVLI(s, b.in, &b.inPos)
		if ret != xzStreamEnd {
			indexUpdate(s, b)
			return ret
		}
		switch s.index.sequence {
		case seqIndexCount:
			s.index.count = s.vli
			if s.index.count != s.block.count {
				return xzDataError
			}
			s.index.sequence = seqIndexUnpadded
		case seqIndexUnpadded:
			s.index.hash.unpadded += s.vli
			s.index.sequence = seqIndexUncompressed
		case seqIndexUncompressed:
			s.index.hash.uncompressed += s.vli
			var buf [2 * 8]byte  
			putLE64(uint64(s.index.hash.unpadded), buf[:])
			putLE64(uint64(s.index.hash.uncompressed), buf[8:])
			_, _ = s.index.hash.sha256.Write(buf[:])
			s.index.count--
			s.index.sequence = seqIndexUnpadded
		}
		if !(s.index.count > 0) {
			break
		}
	}
	return xzStreamEnd
}
/*
Decode the Number of Records, Unpadded Size, and Uncompressed Size
fields from the Index field. That is, Index Padding and CRC32 are not
decoded by this function.

This can return xzOK (more input needed), xzStreamEnd (everything
successfully decoded), or xzDataError (input is corrupt).
package xz
import (
	"bytes"
	"crypto/sha256"
	"hash"
	"hash/crc32"
	"hash/crc64"
)
const (
	streamHeaderSize = 12
	headerMagic      = "\xfd7zXZ\x00"
	footerMagic      = "YZ"
)
type vliType uint64
const (
	vliUnknown vliType = ^vliType(0)
	vliBytesMax = 8 * 8 / 7  
)
type xzDecHash struct {
	unpadded     vliType
	uncompressed vliType
	sha256       hash.Hash
}
type xzDecSeq int
const (
	seqStreamHeader xzDecSeq = iota
	seqBlockStart
	seqBlockHeader
	seqBlockUncompress
	seqBlockPadding
	seqBlockCheck
	seqIndex
	seqIndexPadding
	seqIndexCRC32
	seqStreamFooter
)
type xzDecIndexSeq int
const (
	seqIndexCount xzDecIndexSeq = iota
	seqIndexUnpadded
	seqIndexUncompressed
)
type xzDec struct {
	sequence xzDecSeq
	pos int
	vli vliType
	inStart  int
	outStart int
	crc32 hash.Hash
	checkCRC32  hash.Hash
	checkCRC64  hash.Hash
	checkSHA256 hash.Hash
	check hash.Hash
	*Header
	allowBufError bool
	blockHeader struct {
		compressed vliType
		uncompressed vliType
		size int
	}
	block struct {
		compressed vliType
		uncompressed vliType
		count vliType
		hash xzDecHash
	}
	index struct {
		sequence xzDecIndexSeq
		size vliType
		count vliType
		hash xzDecHash
	}
	temp struct {
		pos      int
		buf      []byte  
		bufArray [1024]byte
	}
	chain func(b *xzBuf) xzRet
	lzma2 *xzDecLZMA2
	bcjs   []*xzDecBCJ
	deltas []*xzDecDelta
	bcjsUsed   int
	deltasUsed int
}
var checkSizes = [...]byte{
	0,
	4, 4, 4,
	8, 8, 8,
	16, 16, 16,
	32, 32, 32,
	64, 64, 64,
}
func fillTemp(s *xzDec, b *xzBuf) bool {
	copySize := len(b.in) - b.inPos
	tempRemaining := len(s.temp.buf) - s.temp.pos
	if copySize > tempRemaining {
		copySize = tempRemaining
	}
	copy(s.temp.buf[s.temp.pos:], b.in[b.inPos:])
	b.inPos += copySize
	s.temp.pos += copySize
	if s.temp.pos == len(s.temp.buf) {
		s.temp.pos = 0
		return true
	}
	return false
}
func decVLI(s *xzDec, in []byte, inPos *int) xzRet {
	var byte byte
	if s.pos == 0 {
		s.vli = 0
	}
	for *inPos < len(in) {
		byte = in[*inPos]
		*inPos++
		s.vli |= vliType(byte&0x7f) << uint(s.pos)
		if byte&0x80 == 0 {
			if byte == 0 && s.pos != 0 {
				return xzDataError
			}
			s.pos = 0
			return xzStreamEnd
		}
		s.pos += 7
		if s.pos == 7*vliBytesMax {
			return xzDataError
		}
	}
	return xzOK
}
func decBlock(s *xzDec, b *xzBuf) xzRet {
	var ret xzRet
	s.inStart = b.inPos
	s.outStart = b.outPos
	ret = s.chain(b)
	s.block.compressed += vliType(b.inPos - s.inStart)
	s.block.uncompressed += vliType(b.outPos - s.outStart)
	if s.block.compressed > s.blockHeader.compressed ||
		s.block.uncompressed > s.blockHeader.uncompressed {
		return xzDataError
	}
	switch s.CheckType {
	case CheckCRC32, CheckCRC64, CheckSHA256:
		_, _ = s.check.Write(b.out[s.outStart:b.outPos])
	}
	if ret == xzStreamEnd {
		if s.blockHeader.compressed != vliUnknown &&
			s.blockHeader.compressed != s.block.compressed {
			return xzDataError
		}
		if s.blockHeader.uncompressed != vliUnknown &&
			s.blockHeader.uncompressed != s.block.uncompressed {
			return xzDataError
		}
		s.block.hash.unpadded +=
			vliType(s.blockHeader.size) + s.block.compressed
		s.block.hash.unpadded += vliType(checkSizes[s.CheckType])
		s.block.hash.uncompressed += s.block.uncompressed
		var buf [2 * 8]byte  
		putLE64(uint64(s.block.hash.unpadded), buf[:])
		putLE64(uint64(s.block.hash.uncompressed), buf[8:])
		_, _ = s.block.hash.sha256.Write(buf[:])
		s.block.count++
	}
	return ret
}
func indexUpdate(s *xzDec, b *xzBuf) {
	inUsed := b.inPos - s.inStart
	s.index.size += vliType(inUsed)
	_, _ = s.crc32.Write(b.in[s.inStart : s.inStart+inUsed])
}