Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
throw new Error("Only v2 pack indexes supported");
}
// Get the number of hashes in index
// This is the value of the last fan-out entry
let hashOffset = 8 + 255 * 4;
const length = readUint32(buffer, hashOffset);
hashOffset += 4;
const crcOffset = hashOffset + 20 * length;
const lengthOffset = crcOffset + 4 * length;
const largeOffset = lengthOffset + 4 * length;
let checkOffset = largeOffset;
const indexes = new Array(length);
for (let i = 0; i < length; i++) {
const start = hashOffset + i * 20;
const hash = bodec.toHex(bodec.slice(buffer, start, start + 20));
const crc = readUint32(buffer, crcOffset + i * 4);
let offset = readUint32(buffer, lengthOffset + i * 4);
if (offset & 0x80000000) {
offset = largeOffset + (offset &0x7fffffff) * 8;
checkOffset = Math.max(checkOffset, offset + 8);
offset = readUint64(buffer, offset);
}
indexes[i] = {
hash: hash,
offset: offset,
crc: crc
};
}
const packChecksum = bodec.toHex(bodec.slice(buffer, checkOffset, checkOffset + 20));
const checksum = bodec.toHex(bodec.slice(buffer, checkOffset + 20, checkOffset + 40));
if (sha1(bodec.slice(buffer, 0, checkOffset + 20)) !== checksum) {
function verifyEncodePack() {
try {
unpackStream(newPack);
if (bodec.toHex(pack) !== bodec.toHex(newPack)) {
throw new Error("Final pack doesn't match original.");
}
}
catch (err) {
console.log(bodec.toHex(pack));
console.log(bodec.toHex(newPack));
throw err;
}
}
]);
function verifyEncodePack() {
try {
unpackStream(newPack);
if (bodec.toHex(pack) !== bodec.toHex(newPack)) {
throw new Error("Final pack doesn't match original.");
}
}
catch (err) {
console.log(bodec.toHex(pack));
console.log(bodec.toHex(newPack));
throw err;
}
}
]);
function verifyEncodePack() {
try {
unpackStream(newPack);
if (bodec.toHex(pack) !== bodec.toHex(newPack)) {
throw new Error("Final pack doesn't match original.");
}
}
catch (err) {
console.log(bodec.toHex(pack));
console.log(bodec.toHex(newPack));
throw err;
}
}
]);
const hash = bodec.toHex(bodec.slice(buffer, start, start + 20));
const crc = readUint32(buffer, crcOffset + i * 4);
let offset = readUint32(buffer, lengthOffset + i * 4);
if (offset & 0x80000000) {
offset = largeOffset + (offset &0x7fffffff) * 8;
checkOffset = Math.max(checkOffset, offset + 8);
offset = readUint64(buffer, offset);
}
indexes[i] = {
hash: hash,
offset: offset,
crc: crc
};
}
const packChecksum = bodec.toHex(bodec.slice(buffer, checkOffset, checkOffset + 20));
const checksum = bodec.toHex(bodec.slice(buffer, checkOffset + 20, checkOffset + 40));
if (sha1(bodec.slice(buffer, 0, checkOffset + 20)) !== checksum) {
throw new Error("Checksum mistmatch");
}
const byHash = {};
indexes.sort((a, b) => a.offset - b.offset);
indexes.forEach(data => {
byHash[data.hash] = {
offset: data.offset,
crc: data.crc,
};
});
const offsets = indexes.map(entry => entry.offset).sort((a, b) => a - b);
return {
offsets: offsets,
export function parseEntry(chunk : Uint8Array) : Entry {
let offset = 0;
let byte = chunk[offset++];
const type = numToType[(byte >> 4) & 0x7];
let size = byte & 0xf;
let left = 4;
while (byte & 0x80) {
byte = chunk[offset++];
size |= (byte & 0x7f) << left;
left += 7;
}
size = size >>> 0;
let ref;
if (type === "ref-delta") {
ref = bodec.toHex(bodec.slice(chunk, offset, offset += 20));
}
else if (type === "ofs-delta") {
byte = chunk[offset++];
ref = byte & 0x7f;
while (byte & 0x80) {
byte = chunk[offset++];
ref = ((ref + 1) << 7) | (byte & 0x7f);
}
}
const body = inflate(bodec.slice(chunk, offset));
if (body.length !== size) {
throw new Error("Size mismatch");
}
const result : any = {
type: type,
let i = 0;
const length = body.length;
let start;
let mode;
let name;
let hash;
const tree : TreeBody = {};
while (i < length) {
start = i;
i = indexOf(body, 0x20, start);
if (i < 0) throw new SyntaxError("Missing space");
mode = parseOct(body, start, i++);
start = i;
i = indexOf(body, 0x00, start);
name = bodec.toUnicode(body, start, i++);
hash = bodec.toHex(body, i, i += 20);
tree[name] = {
mode: mode,
hash: hash
};
}
return tree;
}
var i = 0;
var length = body.length;
var start;
var mode;
var name;
var hash;
var tree = {};
while (i < length) {
start = i;
i = indexOf(body, 0x20, start);
if (i < 0) throw new SyntaxError("Missing space");
mode = parseOct(body, start, i++);
start = i;
i = indexOf(body, 0x00, start);
name = bodec.toUnicode(body, start, i++);
hash = bodec.toHex(body, i, i += 20);
tree[name] = {
mode: mode,
hash: hash
};
}
return tree;
}