Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function EncodeCreateStringTable(packet: CreateStringTablePacket, stream: BitStream) {
stream.writeASCIIString(packet.table.name);
stream.writeUint16(packet.table.maxEntries);
const encodeBits = logBase2(packet.table.maxEntries);
const numEntries = packet.table.entries.filter((entry) => entry).length;
stream.writeBits(numEntries, encodeBits + 1);
let entryData = new BitStream(new ArrayBuffer(guessStringTableEntryLength(packet.table, packet.table.entries)));
encodeStringTableEntries(entryData, packet.table, packet.table.entries);
if (packet.table.compressed) {
const decompressedByteLength = Math.ceil(entryData.length / 8);
entryData.index = 0;
const compressedData = compress(entryData.readArrayBuffer(decompressedByteLength));
entryData = new BitStream(new ArrayBuffer(decompressedByteLength));
entryData.writeUint32(decompressedByteLength);
entryData.writeUint32(compressedData.byteLength + 4); // 4 magic bytes
entryData.writeASCIIString('SNAP', 4);
const typeForce: any = compressedData.buffer;
entryData.writeArrayBuffer(typeForce as BitStream);
}
const entryLength = entryData.index;
entryData.index = 0;
writeVarInt(entryLength, stream);
if (packet.table.fixedUserDataSize || packet.table.fixedUserDataSizeBits) {
stream.writeBoolean(true);
stream.writeBits(packet.table.fixedUserDataSize || 0, 12);
stream.writeBits(packet.table.fixedUserDataSizeBits || 0, 4);
function compress(msg) {
try {
return {
value: SnappyJS.compress(Buffer.from(msg))
}
} catch (error) {
return {
error
}
}
}
function deflate_snappy(value) {
return snappy.compress(value);
}
const _generateLink = (): void => {
const u8a = util.stringToU8a(code);
const compU8a = snappy.compress(u8a);
const compStr = compU8a.reduce((str: string, ch: number): string => {
return str + String.fromCharCode(ch);
}, '');
const base64code = btoa(compStr);
const path = `/js/share/${base64code}`;
if (base64code !== base64) {
history.push(path);
}
const basePath = window.location.pathname.replace('/', '').length > 0
? `${window.location.origin}/${window.location.pathname.replace('/', '')}`
: `${window.location.origin}`;
_copyToClipboard(`${basePath}/#${path}`);