Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
unzip = async () => {
const res = await fetch(
'https://cors-anywhere.herokuapp.com/https://registry.npmjs.org/tiza/download/tiza-2.1.0.tgz',
)
const data = await res.arrayBuffer()
const buffer = await pako.ungzip(data)
// console.log(buffer)
untar(buffer.buffer).then(console.log, console.log, console.log)
// console.log(t)
}
function processBinaryMessage(message) {
var messageBytes = new Uint8Array(message);
// if it's a binary message and first byte it's zero then assume it's a compressed json string
//otherwise is a file and a 'save as' dialog is opened
if (messageBytes[0] == 0) {
var message = pako.ungzip(messageBytes.subarray(1), {to: "string"});
parseAndNotify(message);
}
else {
var fileNameLength = messageBytes[1];
var fileName = String.fromCharCode.apply(null, messageBytes.subarray(2, 2 + fileNameLength));
var blob = new Blob([message]);
FileSaver.saveAs(blob.slice(2 + fileNameLength), fileName);
}
}
}
db.get(lang, function (err, value) {
// err = true
if (err) {
downloadlang(true)
}
else {
while(value[0] == 0x1f && value[1] == 0x8b){
value = pako.ungzip(value)
}
postMessage({
index: index,
'progress': {
loaded_lang_model:1,
cached: true
}
})
Module.FS_createDataFile('tessdata', lang +".traineddata", value, true, false);
loaded_langs.push(lang)
cb(null, lang)
}
})
}
logger.debug("Decompressing payload");
if (metrics !== undefined && metrics !== null) {
for (var i = 0; i < metrics.length; i++) {
if (metrics[i].name === "algorithm") {
algorithm = metrics[i].value;
}
}
}
if (algorithm === null || algorithm.toUpperCase() === "DEFLATE") {
logger.debug("Decompressing with DEFLATE!");
return pako.inflate(payload.body);
} else if (algorithm.toUpperCase() === "GZIP") {
logger.debug("Decompressing with GZIP");
return pako.ungzip(payload.body);
} else {
throw new Error("Unknown or unsupported algorithm " + algorithm);
}
},
async decode(queryParamStr: string): Promise {
const base64String = decodeURIComponent(queryParamStr);
const gziped = Uint8Array.from(atob(base64String), c => c.charCodeAt(0));
const configStr = ungzip(gziped, { to: "string" });
const config = JSON.parse(configStr);
return config;
}
db.get(lang, (err, data) => {
if (err) return getLanguageData(lang, progressMessage, createDataFileCached)
while(data[0] == 0x1f && data[1] == 0x8b) data = ungzip(data);
progressMessage({ loaded_lang_model: lang, from_cache: true })
cb(null, data)
})
})
logger.debug("Decompressing payload");
if (metrics !== undefined && metrics !== null) {
for (var i = 0; i < metrics.length; i++) {
if (metrics[i].name === "algorithm") {
algorithm = metrics[i].value;
}
}
}
if (algorithm === null || algorithm.toUpperCase() === "DEFLATE") {
logger.debug("Decompressing with DEFLATE!");
return pako.inflate(payload.body);
} else if (algorithm.toUpperCase() === "GZIP") {
logger.debug("Decompressing with GZIP");
return pako.ungzip(payload.body);
} else {
throw new Error("Unknown or unsupported algorithm " + algorithm);
}
},
function gzipUncompress(compressedMessage) {
var messageBytes = new Uint8Array(compressedMessage);
var message = pako.ungzip(messageBytes, {to: "string"});
return message;
}
function checkIfGzipped(obj) {
if (typeof obj !== 'boolean' && obj.instanceOf('mtproto.type.Gzip_packed')) {
const packedData = obj.packed_data
const buffer = pako.ungzip(packedData)
Object.setPrototypeOf(buffer, packedData.__proto__)
const Type = tl.TypeBuilder.requireTypeFromBuffer(buffer)
return new Type({ buffer: buffer }).deserialize()
}
else return obj
}