Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Calculate how many digits we need in base 128 and move the pointer
i += Math.floor(Math.log(offset) / Math.log(0x80)) + 1;
// Write the last digit
head[i] = offset & 0x7f;
// Then write the rest
while (offset >>= 7) {
head[--i] = 0x80 | (--offset & 0x7f);
}
}
const parts = [bodec.fromArray(head)];
if (typeof item.ref === "string") {
parts.push(bodec.fromHex(item.ref));
}
parts.push(deflate(item.body));
return bodec.join(parts);
}
}
if (!bodec.isBinary(item)) throw new Error("encode output must be buffers");
outs.push(item);
});
write({num:items.length});
items.forEach(item => {
if (!bodec.isBinary(item.body)) {
item.body = encoders[item.type](item.body);
}
write(item);
});
write();
if (!done) throw new Error("Output stream never ended");
newPack = bodec.join(outs);
},
function verifyEncodePack() {
more = emit({progress: bodec.toUnicode(data, 1)});
}
else if (data[0] === 3) {
more = emit({error: bodec.toUnicode(data, 1)});
}
else {
more = emit(bodec.toUnicode(data).trim());
}
}
}
else if (state === 2) {
if (offset < 4 && byte === PACK[offset++]) {
continue;
}
state = 3;
more = emit(bodec.join([PACK, bodec.subarray(item, i)]));
break;
}
else {
throw new Error("pkt-line decoder in invalid state");
}
}
return more;
};
function stringifyData(data) {
return binaryTo(require('bodec').join(data));
}
stream.on("end", function () {
resolve(bodec.join(chunks));
});
function onWrite(item) {
if (item === undefined) return socket.put();
bodyWrite(item);
socket.take(onWrite);
if (item !== "done\n" || !bodyParts.length) return;
const body = bodec.join(bodyParts);
bodyParts.length = 0;
request("POST", gitUrl + "/" + serviceName, headers, body, onResult);
}
function emitObject() {
const body = bodec.join(parts);
if (body.length !== length) {
throw new Error("Body length mismatch");
}
const item : any = {
type: numToType[type],
size: length,
body: body,
offset: start
};
if (ref) item.ref = ref;
parts.length = 0;
start = 0;
offset = 0;
type = 0;
length = 0;
ref = 0;
function frame(obj) {
var type = obj.type;
var body = obj.body;
if (!bodec.isBinary(body)) body = encoders[type](body);
return bodec.join([
bodec.fromRaw(type + " " + body.length + "\0"),
body
]);
}
function frame(obj : Frame) {
const type = obj.type;
const body = bodec.isBinary(obj.body) ? obj.body : (encoders as any)[type](obj.body) as Uint8Array;
return bodec.join([
bodec.fromRaw(type + " " + body.length + "\0"),
body
]);
}