Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
encode() {
if (this.buffer !== null && this.rawBuffer === null) {
let sectorSize = this.archive.sectorSize,
data = new Uint8Array(this.buffer),
sectorCount = Math.ceil(data.byteLength / sectorSize),
offsets = new Uint32Array(sectorCount + 1),
offset = offsets.byteLength,
chunks = [];
// First offset is right after the offsets list.
offsets[0] = offsets.byteLength;
for (let i = 0; i < sectorCount; i++) {
let sectorOffset = i * sectorSize,
uncompressed = data.subarray(sectorOffset, sectorOffset + sectorSize),
chunk = deflate(uncompressed),
compressedSectorSize = chunk.byteLength + 1;
// If the sector is going to take more than the archive's sector size, don't compress it.
if (compressedSectorSize > sectorSize) {
chunk = uncompressed;
}
offset += compressedSectorSize;
offsets[i + 1] = offset;
chunks[i] = chunk;
}
let compressedSize = offsets[offsets.length - 1],
rawBuffer = new Uint8Array(new ArrayBuffer(compressedSize));
$('.codeblock').each(function () {
var block = $(this),
defaultSrc = $('textarea', block).attr('defaultvalue'),
key = 'src' + (block.attr('step') !== '1' ? block.attr('step') : '');
var src = $('.CodeMirror', block).length ? $('.CodeMirror', block)[0].CodeMirror.getValue() : $('textarea', block).val().trim();
if (src !== defaultSrc) {
var comp = btoa(pako.deflate(src, {to: 'string', level: 9, raw: true}));
/* instead of using regular base64, convert /, +, and = to ., -, and _
* so that they don't need to be escaped on the url. This reduces the
* average length of the url by 6 percent. */
comp = comp.replace(/\//g, '.').replace(/\+/g, '-').replace(/=/g, '_');
newQuery[key] = comp;
}
});
if (!inPop) {
generateDebugLink(outerShape, holes, options){
if(options.debug){
try{
const pako = require("pako");
const data64 = pako.deflate(JSON.stringify({ holes, outerShape, doNotBuild: options.doNotBuild }));
const urlParam = `data=${encodeURIComponent(data64)}`;
console.info(`Holes in debug: https://wanadev.github.io/holes-in/debugPage.html?${urlParam}`);
}catch(error) {
console.warn("error on holes-in generate debug link. You may need to install pako", error)
}
}
},
send(topic: string, data: any) {
/**
* Enhanced transport
*/
const json = JSON.stringify(data)
let transport = `${topic}${json ? ':' + json : ''}`
if (
global.config.compression &&
!this.session.debug &&
!/^core|auth$/.test(topic)
) {
transport =
'#' +
pako.deflate(transport, {
to: 'string'
})
}
try {
/**
* Basic RAW transport
*/
if (/^core|auth$/.test(topic)) {
if (this.session.version === 0) {
/**
* Payload version 0
*/
transport = JSON.stringify({
d: data
})
} else {
function deflate (config: AppConfig): AppConfigCompressed {
return {
v: 1,
d: pako.deflate(JSON.stringify(config), { to: 'string' })
}
}
function wrapObject({ type, object /*: {type: string, object: Buffer} */ }) {
let buffer$$1 = Buffer.concat([Buffer.from(type + ' '), Buffer.from(object.byteLength.toString()), Buffer.from([0]), Buffer.from(object)]);
let oid = shasum(buffer$$1);
return {
oid,
file: Buffer.from(pako.deflate(buffer$$1))
};
}
protected toEprops(params:unknown):{ eprops:string } {
const deflatedArray = Pako.deflate(JSON.stringify(params));
const compressed = base64.bytesToBase64(deflatedArray)
return { eprops: compressed };
}
}
function serializeArray(obj) {
return {
dtype: _.invert(typesToArray)[obj.data.constructor],
compressed_buffer: pako.deflate(obj.data.buffer, {level: 9}),
shape: obj.shape
};
}
encode = () => {
this.dictionary.set(PDFName.from('Filter'), PDFName.from('FlateDecode'));
const buffer = new Uint8Array(this.operatorsBytesSize());
this.copyOperatorBytesInto(buffer);
this.encodedOperators = pako.deflate(buffer);
this.dictionary.set(
'Length',
PDFNumber.fromNumber(this.encodedOperators.length),
);
return this;
};
function compressAbi(abi) {
return Buffer.from(pako.deflate(JSON.stringify(abi))).toString('base64');
}