func readFanout(idx *Idxfile, r io.Reader) error { var err error for i := 0; i < 255; i++ { idx.Fanout[i], err = binary.ReadUint32(r) if err != nil { return err } } idx.ObjectCount, err = binary.ReadUint32(r) return err }
func (d *Decoder) getExtensionReader() (io.Reader, error) { len, err := binary.ReadUint32(d.r) if err != nil { return nil, err } return &io.LimitedReader{R: d.r, N: int64(len)}, nil }
func readVersion(idx *Idxfile, r io.Reader) error { v, err := binary.ReadUint32(r) if err != nil { return err } if v > VersionSupported { return ErrUnsupportedVersion } idx.Version = v return nil }
func readOffsets(idx *Idxfile, r io.Reader) error { c := int(idx.ObjectCount) for i := 0; i < c; i++ { o, err := binary.ReadUint32(r) if err != nil { return err } idx.Entries[i].Offset = uint64(o) } return nil }
// Decode reads the whole index object from its input and stores it in the // value pointed to by idx. func (d *Decoder) Decode(idx *Index) error { var err error idx.Version, err = validateHeader(d.r) if err != nil { return err } entryCount, err := binary.ReadUint32(d.r) if err != nil { return err } if err := d.readEntries(idx, int(entryCount)); err != nil { return err } return d.readExtensions(idx) }
func validateHeader(r io.Reader) (version uint32, err error) { var s = make([]byte, 4) if _, err := io.ReadFull(r, s); err != nil { return 0, err } if !bytes.Equal(s, indexSignature) { return 0, ErrMalformedSignature } version, err = binary.ReadUint32(r) if err != nil { return 0, err } if version < DecodeVersionSupported.Min || version > DecodeVersionSupported.Max { return 0, ErrUnsupportedVersion } return }
// readCount reads and returns the count of objects field of a packfile. func (s *Scanner) readCount() (uint32, error) { return binary.ReadUint32(s.r) }
// readVersion reads and returns the version field of a packfile. func (s *Scanner) readVersion() (uint32, error) { return binary.ReadUint32(s.r) }