private void VerifyPack() { using (GitPackReader reader = new GitPackReader(File.OpenRead(Path))) { string header; int version, numberOfObjects; header = reader.ReadBytes(4).GetString(); version = reader.ReadBytes(4).Sum(b => b); numberOfObjects = reader.ReadBytes(4).Sum(b => b); if (Version != version) { throw new PackFileException(String.Format("Bad version number {0}. Was expecting {1}", version, Version), Path); } if (HEADER != header) { throw new PackFileException("Invalid header for pack-file. Needs to be: 'PACK'", Path); } } }
private void Load() { string magicNumber; int version; using (GitPackReader reader = new GitPackReader(File.OpenRead(Path))) { magicNumber = reader.ReadBytes(4).GetString(); version = reader.ReadBytes(4).Sum(b => b); if (Version != version) { throw new PackFileException(String.Format("Bad version number {0}. Was expecting {1}", version, Version), Path); } if (MAGIC_NUMBER != magicNumber) { throw new PackFileException("Invalid header for pack-file. Needs to be: 'PACK'", Path); } #region Fanout Table fanout = new int[FANOUT]; shas = new int[FANOUT][]; offsets = new byte[FANOUT][]; crcs = new byte[FANOUT][]; // one big read, faster as 256 small 4 byte read statements ? byte[] fanoutRaw = new byte[FANOUT * 4]; fanoutRaw = reader.ReadBytes(FANOUT * 4); for (int idx = 0; idx < FANOUT; idx++) { fanout[idx] = System.Net.IPAddress.HostToNetworkOrder(BitConverter.ToInt32(fanoutRaw, idx * 4)); } #endregion NumberOfObjects = fanout[FANOUT - 1]; #region SHA's for (int idx = 0; idx < FANOUT; idx++) { int bucketCount; if (idx == 0) { bucketCount = fanout[idx]; } else { bucketCount = fanout[idx] - fanout[idx - 1]; } if (bucketCount == 0) { shas[idx] = new int[] { }; crcs[idx] = new byte[] { }; offsets[idx] = new byte[] { }; continue; } int recordLength = bucketCount * 20; int[] bin = new int[recordLength >> 2]; byte[] rawRecord = reader.ReadBytes(recordLength); for (int i = 0; i < bin.Length; i++) { bin[i] = System.Net.IPAddress.HostToNetworkOrder(BitConverter.ToInt32(rawRecord, i << 2)); } shas[idx] = bin; offsets[idx] = new byte[bucketCount * 4]; crcs[idx] = new byte[bucketCount * 4]; } #endregion #region CRC32 for (int idx = 0; idx < FANOUT; idx++) { crcs[idx] = reader.ReadBytes(crcs[idx].Length); } #endregion #region 32 bit offset table for (int idx = 0; idx < FANOUT; idx++) { offsets[idx] = reader.ReadBytes(offsets[idx].Length); } #endregion // TODO: Support 64 bit tables string packChecksum = reader.ReadBytes(20).GetString(); string idxChecksum = reader.ReadBytes(20).GetString(); } }
private void Load() { string magicNumber; int version; using (GitPackReader reader = new GitPackReader(File.OpenRead(Path))) { magicNumber = reader.ReadBytes(4).GetString(); version = reader.ReadBytes(4).Sum(b => b); if (Version != version) throw new PackFileException(String.Format("Bad version number {0}. Was expecting {1}", version, Version), Path); if (MAGIC_NUMBER != magicNumber) throw new PackFileException("Invalid header for pack-file. Needs to be: 'PACK'", Path); #region Fanout Table fanout = new int[FANOUT]; shas = new int[FANOUT][]; offsets = new byte[FANOUT][]; crcs = new byte[FANOUT][]; // one big read, faster as 256 small 4 byte read statements ? byte[] fanoutRaw = new byte[FANOUT * 4]; fanoutRaw = reader.ReadBytes(FANOUT * 4); for (int idx = 0; idx < FANOUT; idx++) fanout[idx] = System.Net.IPAddress.HostToNetworkOrder(BitConverter.ToInt32(fanoutRaw, idx * 4)); #endregion NumberOfObjects = fanout[FANOUT - 1]; #region SHA's for (int idx = 0; idx < FANOUT; idx++) { int bucketCount; if (idx == 0) bucketCount = fanout[idx]; else bucketCount = fanout[idx] - fanout[idx - 1]; if (bucketCount == 0) { shas[idx] = new int[] { }; crcs[idx] = new byte[] { }; offsets[idx] = new byte[] { }; continue; } int recordLength = bucketCount * 20; int[] bin = new int[recordLength >> 2]; byte[] rawRecord = reader.ReadBytes(recordLength); for (int i = 0; i < bin.Length; i++) { bin[i] = System.Net.IPAddress.HostToNetworkOrder(BitConverter.ToInt32(rawRecord, i << 2)); } shas[idx] = bin; offsets[idx] = new byte[bucketCount * 4]; crcs[idx] = new byte[bucketCount * 4]; } #endregion #region CRC32 for (int idx = 0; idx < FANOUT; idx++) crcs[idx] = reader.ReadBytes(crcs[idx].Length); #endregion #region 32 bit offset table for (int idx = 0; idx < FANOUT; idx++) offsets[idx] = reader.ReadBytes(offsets[idx].Length); #endregion // TODO: Support 64 bit tables string packChecksum = reader.ReadBytes(20).GetString(); string idxChecksum = reader.ReadBytes(20).GetString(); } }
private void VerifyPack() { using (GitPackReader reader = new GitPackReader(File.OpenRead(Path))) { string header; int version, numberOfObjects; header = reader.ReadBytes(4).GetString(); version = reader.ReadBytes(4).Sum(b => b); numberOfObjects = reader.ReadBytes(4).Sum(b => b); if (Version != version) throw new PackFileException(String.Format("Bad version number {0}. Was expecting {1}", version, Version), Path); if (HEADER != header) throw new PackFileException("Invalid header for pack-file. Needs to be: 'PACK'", Path); } }