Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
time: 100,
});
let progressFactor = entry.compressedSize / zipfile.fileSize;
progressStream.on("progress", info => {
opts.onProgress({
progress: progressOffset + (info.percentage / 100) * progressFactor,
});
});
progressStream.pipe(dst);
src.pipe(progressStream);
await sf.promised(dst);
progressOffset += progressFactor;
await sf.chmod(entryPath, 0o755);
const fileBuffer = await sf.readFile(entryPath, { encoding: null });
const signedHash = crc32.buf(fileBuffer);
// this converts an int32 to an uint32 (which is what yauzl reports)
const hash = new Uint32Array([signedHash])[0];
if (hash !== entry.crc32) {
await sf.unlink(entryPath);
throw new Error(
`CRC32 mismatch for ${entry.fileName}: expected ${
entry.crc32
} got ${hash}`
);
}
};
fragCount = 0;
}
let onlyBody;
let opcode = data[4];
let subopcode = data[5];
let didSent = false;
if (opcode == 0x42) { // COMPRESSED_PACKAGE
const body = unit.queue(data.slice(5, 4 + length));
let len = body.int();
let realLen = body.int();
let crc = body.int();
let compressedData = body.skip(len);
let uncompressedData = lzfjs.decompress(new Uint8Array(compressedData));
let crcUncompressedData = crc32.buf(uncompressedData, ~-1);
// if (crcUncompressedData != crc || uncompressedData.length != realLen || compressedData.length != len) {
// throw new Error('invalid compressed data!');
// }
data = [0xAA, 0x55, ...unit.short(realLen), ...Array.from(uncompressedData), 0x55, 0xAA, ...data.slice(6 + length)]
client.debug('data uncompressed | ' + Array.from(data).map(x => x.toString(16).padStart(2, '0').toUpperCase()).join(' '));
opcode = data[4];
subopcode = data[5];
length = realLen;
}
for (let i = 0; i < waitingTasks.length; i++) {
let task = waitingTasks[i];
if (task.opcode) {
if (opcode != task.opcode) continue;
socket.sendCompressed = function (response) {
let crc = crc32.buf(response, ~-1);
let compressed = lzfjs.compress(response);
socket.send([
0x42, // COMPRESSED_PACKAGE
...unit.int(compressed.length),
...unit.int(response.length),
...unit.int(crc),
...compressed
]);
}
function checksum(x) {
// crc32 returns a signed integer - need to cast it to unsigned
// Note that this uses the default 0xedb88320 polynomial
return crc32.buf(x) >>> 0; // Need this to be a uint, hence the bit shift
}
it("should test upload and download of a file", async () => {
let teamspeak: TeamSpeak|null = null
try {
teamspeak = await TeamSpeak.connect({
...config,
protocol: QueryProtocol.RAW,
queryport: parseInt(process.env.TS3_QUERYPORT_RAW!, 10) || 10011,
nickname: "JEST RAW"
})
const data = fs.readFileSync(`${__dirname}/mocks/filetransfer.png`)
const crc = crc32.buf(data)
await teamspeak.uploadFile(`/icon_${crc >>> 0}`, data, 0)
const download = await teamspeak.downloadIcon(`icon_${crc >>> 0}`)
expect(crc).toEqual(crc32.buf(download))
teamspeak.forceQuit()
} catch (e) {
if (teamspeak instanceof TeamSpeak) teamspeak.forceQuit()
throw e
}
await wait(2000)
})
it("should test upload and download of a file", async () => {
if (!(ts3 instanceof TeamSpeak3))
throw new Error("can not run test, due to no valid connection")
const data = fs.readFileSync(`${__dirname}/mocks/filetransfer.png`)
const crc = crc32.buf(data)
await ts3.uploadFile(`/icon_${crc >>> 0}`, data, 0)
const download = await ts3.downloadIcon(`icon_${crc >>> 0}`)
assert.equal(crc, crc32.buf(download))
}).timeout(5000)
].forEach(path => {
if(!CFB.find(cfb1, path)) return;
const d1 = CFB.find(cfb1, path).content, c1 = buf(d1);
const d2 = CFB.find(cfb2, path).content, c2 = buf(d2);
if(c1 === c2) return;
console.log(path); console.log(d1); console.log(d2);
throw sprintf("%s mismatch: %08X != %08X", path, c1, c2);
});
const crc32Unsigned = input => crc32.buf(input) >>> 0
function getCheckSum(input) {
return crc32.buf(input) >>> 0
}