Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93

Warning: Undefined array key "page_file_edit_line" in /home/sportsfever/public_html/filemanger/edit_text_line.php on line 32
/home/sportsfe.../httpdocs/clone/wp-conte.../plugins/embedpre.../assets/pdf/build
File: pdf.worker.js
}
[40500] Fix | Delete
class CipherTransform {
[40501] Fix | Delete
constructor(stringCipherConstructor, streamCipherConstructor) {
[40502] Fix | Delete
this.StringCipherConstructor = stringCipherConstructor;
[40503] Fix | Delete
this.StreamCipherConstructor = streamCipherConstructor;
[40504] Fix | Delete
}
[40505] Fix | Delete
createStream(stream, length) {
[40506] Fix | Delete
const cipher = new this.StreamCipherConstructor();
[40507] Fix | Delete
return new DecryptStream(stream, length, function cipherTransformDecryptStream(data, finalize) {
[40508] Fix | Delete
return cipher.decryptBlock(data, finalize);
[40509] Fix | Delete
});
[40510] Fix | Delete
}
[40511] Fix | Delete
decryptString(s) {
[40512] Fix | Delete
const cipher = new this.StringCipherConstructor();
[40513] Fix | Delete
let data = stringToBytes(s);
[40514] Fix | Delete
data = cipher.decryptBlock(data, true);
[40515] Fix | Delete
return bytesToString(data);
[40516] Fix | Delete
}
[40517] Fix | Delete
encryptString(s) {
[40518] Fix | Delete
const cipher = new this.StringCipherConstructor();
[40519] Fix | Delete
if (cipher instanceof AESBaseCipher) {
[40520] Fix | Delete
const strLen = s.length;
[40521] Fix | Delete
const pad = 16 - strLen % 16;
[40522] Fix | Delete
s += String.fromCharCode(pad).repeat(pad);
[40523] Fix | Delete
const iv = new Uint8Array(16);
[40524] Fix | Delete
if (typeof crypto !== "undefined") {
[40525] Fix | Delete
crypto.getRandomValues(iv);
[40526] Fix | Delete
} else {
[40527] Fix | Delete
for (let i = 0; i < 16; i++) {
[40528] Fix | Delete
iv[i] = Math.floor(256 * Math.random());
[40529] Fix | Delete
}
[40530] Fix | Delete
}
[40531] Fix | Delete
let data = stringToBytes(s);
[40532] Fix | Delete
data = cipher.encrypt(data, iv);
[40533] Fix | Delete
const buf = new Uint8Array(16 + data.length);
[40534] Fix | Delete
buf.set(iv);
[40535] Fix | Delete
buf.set(data, 16);
[40536] Fix | Delete
return bytesToString(buf);
[40537] Fix | Delete
}
[40538] Fix | Delete
let data = stringToBytes(s);
[40539] Fix | Delete
data = cipher.encrypt(data);
[40540] Fix | Delete
return bytesToString(data);
[40541] Fix | Delete
}
[40542] Fix | Delete
}
[40543] Fix | Delete
class CipherTransformFactory {
[40544] Fix | Delete
static #defaultPasswordBytes = new Uint8Array([0x28, 0xbf, 0x4e, 0x5e, 0x4e, 0x75, 0x8a, 0x41, 0x64, 0x00, 0x4e, 0x56, 0xff, 0xfa, 0x01, 0x08, 0x2e, 0x2e, 0x00, 0xb6, 0xd0, 0x68, 0x3e, 0x80, 0x2f, 0x0c, 0xa9, 0xfe, 0x64, 0x53, 0x69, 0x7a]);
[40545] Fix | Delete
#createEncryptionKey20(revision, password, ownerPassword, ownerValidationSalt, ownerKeySalt, uBytes, userPassword, userValidationSalt, userKeySalt, ownerEncryption, userEncryption, perms) {
[40546] Fix | Delete
if (password) {
[40547] Fix | Delete
const passwordLength = Math.min(127, password.length);
[40548] Fix | Delete
password = password.subarray(0, passwordLength);
[40549] Fix | Delete
} else {
[40550] Fix | Delete
password = [];
[40551] Fix | Delete
}
[40552] Fix | Delete
const pdfAlgorithm = revision === 6 ? new PDF20() : new PDF17();
[40553] Fix | Delete
if (pdfAlgorithm.checkUserPassword(password, userValidationSalt, userPassword)) {
[40554] Fix | Delete
return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
[40555] Fix | Delete
} else if (password.length && pdfAlgorithm.checkOwnerPassword(password, ownerValidationSalt, uBytes, ownerPassword)) {
[40556] Fix | Delete
return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes, ownerEncryption);
[40557] Fix | Delete
}
[40558] Fix | Delete
return null;
[40559] Fix | Delete
}
[40560] Fix | Delete
#prepareKeyData(fileId, password, ownerPassword, userPassword, flags, revision, keyLength, encryptMetadata) {
[40561] Fix | Delete
const hashDataSize = 40 + ownerPassword.length + fileId.length;
[40562] Fix | Delete
const hashData = new Uint8Array(hashDataSize);
[40563] Fix | Delete
let i = 0,
[40564] Fix | Delete
j,
[40565] Fix | Delete
n;
[40566] Fix | Delete
if (password) {
[40567] Fix | Delete
n = Math.min(32, password.length);
[40568] Fix | Delete
for (; i < n; ++i) {
[40569] Fix | Delete
hashData[i] = password[i];
[40570] Fix | Delete
}
[40571] Fix | Delete
}
[40572] Fix | Delete
j = 0;
[40573] Fix | Delete
while (i < 32) {
[40574] Fix | Delete
hashData[i++] = CipherTransformFactory.#defaultPasswordBytes[j++];
[40575] Fix | Delete
}
[40576] Fix | Delete
for (j = 0, n = ownerPassword.length; j < n; ++j) {
[40577] Fix | Delete
hashData[i++] = ownerPassword[j];
[40578] Fix | Delete
}
[40579] Fix | Delete
hashData[i++] = flags & 0xff;
[40580] Fix | Delete
hashData[i++] = flags >> 8 & 0xff;
[40581] Fix | Delete
hashData[i++] = flags >> 16 & 0xff;
[40582] Fix | Delete
hashData[i++] = flags >>> 24 & 0xff;
[40583] Fix | Delete
for (j = 0, n = fileId.length; j < n; ++j) {
[40584] Fix | Delete
hashData[i++] = fileId[j];
[40585] Fix | Delete
}
[40586] Fix | Delete
if (revision >= 4 && !encryptMetadata) {
[40587] Fix | Delete
hashData[i++] = 0xff;
[40588] Fix | Delete
hashData[i++] = 0xff;
[40589] Fix | Delete
hashData[i++] = 0xff;
[40590] Fix | Delete
hashData[i++] = 0xff;
[40591] Fix | Delete
}
[40592] Fix | Delete
let hash = calculateMD5(hashData, 0, i);
[40593] Fix | Delete
const keyLengthInBytes = keyLength >> 3;
[40594] Fix | Delete
if (revision >= 3) {
[40595] Fix | Delete
for (j = 0; j < 50; ++j) {
[40596] Fix | Delete
hash = calculateMD5(hash, 0, keyLengthInBytes);
[40597] Fix | Delete
}
[40598] Fix | Delete
}
[40599] Fix | Delete
const encryptionKey = hash.subarray(0, keyLengthInBytes);
[40600] Fix | Delete
let cipher, checkData;
[40601] Fix | Delete
if (revision >= 3) {
[40602] Fix | Delete
for (i = 0; i < 32; ++i) {
[40603] Fix | Delete
hashData[i] = CipherTransformFactory.#defaultPasswordBytes[i];
[40604] Fix | Delete
}
[40605] Fix | Delete
for (j = 0, n = fileId.length; j < n; ++j) {
[40606] Fix | Delete
hashData[i++] = fileId[j];
[40607] Fix | Delete
}
[40608] Fix | Delete
cipher = new ARCFourCipher(encryptionKey);
[40609] Fix | Delete
checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
[40610] Fix | Delete
n = encryptionKey.length;
[40611] Fix | Delete
const derivedKey = new Uint8Array(n);
[40612] Fix | Delete
for (j = 1; j <= 19; ++j) {
[40613] Fix | Delete
for (let k = 0; k < n; ++k) {
[40614] Fix | Delete
derivedKey[k] = encryptionKey[k] ^ j;
[40615] Fix | Delete
}
[40616] Fix | Delete
cipher = new ARCFourCipher(derivedKey);
[40617] Fix | Delete
checkData = cipher.encryptBlock(checkData);
[40618] Fix | Delete
}
[40619] Fix | Delete
for (j = 0, n = checkData.length; j < n; ++j) {
[40620] Fix | Delete
if (userPassword[j] !== checkData[j]) {
[40621] Fix | Delete
return null;
[40622] Fix | Delete
}
[40623] Fix | Delete
}
[40624] Fix | Delete
} else {
[40625] Fix | Delete
cipher = new ARCFourCipher(encryptionKey);
[40626] Fix | Delete
checkData = cipher.encryptBlock(CipherTransformFactory.#defaultPasswordBytes);
[40627] Fix | Delete
for (j = 0, n = checkData.length; j < n; ++j) {
[40628] Fix | Delete
if (userPassword[j] !== checkData[j]) {
[40629] Fix | Delete
return null;
[40630] Fix | Delete
}
[40631] Fix | Delete
}
[40632] Fix | Delete
}
[40633] Fix | Delete
return encryptionKey;
[40634] Fix | Delete
}
[40635] Fix | Delete
#decodeUserPassword(password, ownerPassword, revision, keyLength) {
[40636] Fix | Delete
const hashData = new Uint8Array(32);
[40637] Fix | Delete
let i = 0;
[40638] Fix | Delete
const n = Math.min(32, password.length);
[40639] Fix | Delete
for (; i < n; ++i) {
[40640] Fix | Delete
hashData[i] = password[i];
[40641] Fix | Delete
}
[40642] Fix | Delete
let j = 0;
[40643] Fix | Delete
while (i < 32) {
[40644] Fix | Delete
hashData[i++] = CipherTransformFactory.#defaultPasswordBytes[j++];
[40645] Fix | Delete
}
[40646] Fix | Delete
let hash = calculateMD5(hashData, 0, i);
[40647] Fix | Delete
const keyLengthInBytes = keyLength >> 3;
[40648] Fix | Delete
if (revision >= 3) {
[40649] Fix | Delete
for (j = 0; j < 50; ++j) {
[40650] Fix | Delete
hash = calculateMD5(hash, 0, hash.length);
[40651] Fix | Delete
}
[40652] Fix | Delete
}
[40653] Fix | Delete
let cipher, userPassword;
[40654] Fix | Delete
if (revision >= 3) {
[40655] Fix | Delete
userPassword = ownerPassword;
[40656] Fix | Delete
const derivedKey = new Uint8Array(keyLengthInBytes);
[40657] Fix | Delete
for (j = 19; j >= 0; j--) {
[40658] Fix | Delete
for (let k = 0; k < keyLengthInBytes; ++k) {
[40659] Fix | Delete
derivedKey[k] = hash[k] ^ j;
[40660] Fix | Delete
}
[40661] Fix | Delete
cipher = new ARCFourCipher(derivedKey);
[40662] Fix | Delete
userPassword = cipher.encryptBlock(userPassword);
[40663] Fix | Delete
}
[40664] Fix | Delete
} else {
[40665] Fix | Delete
cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
[40666] Fix | Delete
userPassword = cipher.encryptBlock(ownerPassword);
[40667] Fix | Delete
}
[40668] Fix | Delete
return userPassword;
[40669] Fix | Delete
}
[40670] Fix | Delete
#buildObjectKey(num, gen, encryptionKey, isAes = false) {
[40671] Fix | Delete
const key = new Uint8Array(encryptionKey.length + 9);
[40672] Fix | Delete
const n = encryptionKey.length;
[40673] Fix | Delete
let i;
[40674] Fix | Delete
for (i = 0; i < n; ++i) {
[40675] Fix | Delete
key[i] = encryptionKey[i];
[40676] Fix | Delete
}
[40677] Fix | Delete
key[i++] = num & 0xff;
[40678] Fix | Delete
key[i++] = num >> 8 & 0xff;
[40679] Fix | Delete
key[i++] = num >> 16 & 0xff;
[40680] Fix | Delete
key[i++] = gen & 0xff;
[40681] Fix | Delete
key[i++] = gen >> 8 & 0xff;
[40682] Fix | Delete
if (isAes) {
[40683] Fix | Delete
key[i++] = 0x73;
[40684] Fix | Delete
key[i++] = 0x41;
[40685] Fix | Delete
key[i++] = 0x6c;
[40686] Fix | Delete
key[i++] = 0x54;
[40687] Fix | Delete
}
[40688] Fix | Delete
const hash = calculateMD5(key, 0, i);
[40689] Fix | Delete
return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
[40690] Fix | Delete
}
[40691] Fix | Delete
#buildCipherConstructor(cf, name, num, gen, key) {
[40692] Fix | Delete
if (!(name instanceof Name)) {
[40693] Fix | Delete
throw new FormatError("Invalid crypt filter name.");
[40694] Fix | Delete
}
[40695] Fix | Delete
const self = this;
[40696] Fix | Delete
const cryptFilter = cf.get(name.name);
[40697] Fix | Delete
const cfm = cryptFilter?.get("CFM");
[40698] Fix | Delete
if (!cfm || cfm.name === "None") {
[40699] Fix | Delete
return function () {
[40700] Fix | Delete
return new NullCipher();
[40701] Fix | Delete
};
[40702] Fix | Delete
}
[40703] Fix | Delete
if (cfm.name === "V2") {
[40704] Fix | Delete
return function () {
[40705] Fix | Delete
return new ARCFourCipher(self.#buildObjectKey(num, gen, key, false));
[40706] Fix | Delete
};
[40707] Fix | Delete
}
[40708] Fix | Delete
if (cfm.name === "AESV2") {
[40709] Fix | Delete
return function () {
[40710] Fix | Delete
return new AES128Cipher(self.#buildObjectKey(num, gen, key, true));
[40711] Fix | Delete
};
[40712] Fix | Delete
}
[40713] Fix | Delete
if (cfm.name === "AESV3") {
[40714] Fix | Delete
return function () {
[40715] Fix | Delete
return new AES256Cipher(key);
[40716] Fix | Delete
};
[40717] Fix | Delete
}
[40718] Fix | Delete
throw new FormatError("Unknown crypto method");
[40719] Fix | Delete
}
[40720] Fix | Delete
constructor(dict, fileId, password) {
[40721] Fix | Delete
const filter = dict.get("Filter");
[40722] Fix | Delete
if (!isName(filter, "Standard")) {
[40723] Fix | Delete
throw new FormatError("unknown encryption method");
[40724] Fix | Delete
}
[40725] Fix | Delete
this.filterName = filter.name;
[40726] Fix | Delete
this.dict = dict;
[40727] Fix | Delete
const algorithm = dict.get("V");
[40728] Fix | Delete
if (!Number.isInteger(algorithm) || algorithm !== 1 && algorithm !== 2 && algorithm !== 4 && algorithm !== 5) {
[40729] Fix | Delete
throw new FormatError("unsupported encryption algorithm");
[40730] Fix | Delete
}
[40731] Fix | Delete
this.algorithm = algorithm;
[40732] Fix | Delete
let keyLength = dict.get("Length");
[40733] Fix | Delete
if (!keyLength) {
[40734] Fix | Delete
if (algorithm <= 3) {
[40735] Fix | Delete
keyLength = 40;
[40736] Fix | Delete
} else {
[40737] Fix | Delete
const cfDict = dict.get("CF");
[40738] Fix | Delete
const streamCryptoName = dict.get("StmF");
[40739] Fix | Delete
if (cfDict instanceof Dict && streamCryptoName instanceof Name) {
[40740] Fix | Delete
cfDict.suppressEncryption = true;
[40741] Fix | Delete
const handlerDict = cfDict.get(streamCryptoName.name);
[40742] Fix | Delete
keyLength = handlerDict?.get("Length") || 128;
[40743] Fix | Delete
if (keyLength < 40) {
[40744] Fix | Delete
keyLength <<= 3;
[40745] Fix | Delete
}
[40746] Fix | Delete
}
[40747] Fix | Delete
}
[40748] Fix | Delete
}
[40749] Fix | Delete
if (!Number.isInteger(keyLength) || keyLength < 40 || keyLength % 8 !== 0) {
[40750] Fix | Delete
throw new FormatError("invalid key length");
[40751] Fix | Delete
}
[40752] Fix | Delete
const ownerBytes = stringToBytes(dict.get("O")),
[40753] Fix | Delete
userBytes = stringToBytes(dict.get("U"));
[40754] Fix | Delete
const ownerPassword = ownerBytes.subarray(0, 32);
[40755] Fix | Delete
const userPassword = userBytes.subarray(0, 32);
[40756] Fix | Delete
const flags = dict.get("P");
[40757] Fix | Delete
const revision = dict.get("R");
[40758] Fix | Delete
const encryptMetadata = (algorithm === 4 || algorithm === 5) && dict.get("EncryptMetadata") !== false;
[40759] Fix | Delete
this.encryptMetadata = encryptMetadata;
[40760] Fix | Delete
const fileIdBytes = stringToBytes(fileId);
[40761] Fix | Delete
let passwordBytes;
[40762] Fix | Delete
if (password) {
[40763] Fix | Delete
if (revision === 6) {
[40764] Fix | Delete
try {
[40765] Fix | Delete
password = utf8StringToString(password);
[40766] Fix | Delete
} catch {
[40767] Fix | Delete
warn("CipherTransformFactory: Unable to convert UTF8 encoded password.");
[40768] Fix | Delete
}
[40769] Fix | Delete
}
[40770] Fix | Delete
passwordBytes = stringToBytes(password);
[40771] Fix | Delete
}
[40772] Fix | Delete
let encryptionKey;
[40773] Fix | Delete
if (algorithm !== 5) {
[40774] Fix | Delete
encryptionKey = this.#prepareKeyData(fileIdBytes, passwordBytes, ownerPassword, userPassword, flags, revision, keyLength, encryptMetadata);
[40775] Fix | Delete
} else {
[40776] Fix | Delete
const ownerValidationSalt = ownerBytes.subarray(32, 40);
[40777] Fix | Delete
const ownerKeySalt = ownerBytes.subarray(40, 48);
[40778] Fix | Delete
const uBytes = userBytes.subarray(0, 48);
[40779] Fix | Delete
const userValidationSalt = userBytes.subarray(32, 40);
[40780] Fix | Delete
const userKeySalt = userBytes.subarray(40, 48);
[40781] Fix | Delete
const ownerEncryption = stringToBytes(dict.get("OE"));
[40782] Fix | Delete
const userEncryption = stringToBytes(dict.get("UE"));
[40783] Fix | Delete
const perms = stringToBytes(dict.get("Perms"));
[40784] Fix | Delete
encryptionKey = this.#createEncryptionKey20(revision, passwordBytes, ownerPassword, ownerValidationSalt, ownerKeySalt, uBytes, userPassword, userValidationSalt, userKeySalt, ownerEncryption, userEncryption, perms);
[40785] Fix | Delete
}
[40786] Fix | Delete
if (!encryptionKey && !password) {
[40787] Fix | Delete
throw new PasswordException("No password given", PasswordResponses.NEED_PASSWORD);
[40788] Fix | Delete
} else if (!encryptionKey && password) {
[40789] Fix | Delete
const decodedPassword = this.#decodeUserPassword(passwordBytes, ownerPassword, revision, keyLength);
[40790] Fix | Delete
encryptionKey = this.#prepareKeyData(fileIdBytes, decodedPassword, ownerPassword, userPassword, flags, revision, keyLength, encryptMetadata);
[40791] Fix | Delete
}
[40792] Fix | Delete
if (!encryptionKey) {
[40793] Fix | Delete
throw new PasswordException("Incorrect Password", PasswordResponses.INCORRECT_PASSWORD);
[40794] Fix | Delete
}
[40795] Fix | Delete
this.encryptionKey = encryptionKey;
[40796] Fix | Delete
if (algorithm >= 4) {
[40797] Fix | Delete
const cf = dict.get("CF");
[40798] Fix | Delete
if (cf instanceof Dict) {
[40799] Fix | Delete
cf.suppressEncryption = true;
[40800] Fix | Delete
}
[40801] Fix | Delete
this.cf = cf;
[40802] Fix | Delete
this.stmf = dict.get("StmF") || Name.get("Identity");
[40803] Fix | Delete
this.strf = dict.get("StrF") || Name.get("Identity");
[40804] Fix | Delete
this.eff = dict.get("EFF") || this.stmf;
[40805] Fix | Delete
}
[40806] Fix | Delete
}
[40807] Fix | Delete
createCipherTransform(num, gen) {
[40808] Fix | Delete
if (this.algorithm === 4 || this.algorithm === 5) {
[40809] Fix | Delete
return new CipherTransform(this.#buildCipherConstructor(this.cf, this.strf, num, gen, this.encryptionKey), this.#buildCipherConstructor(this.cf, this.stmf, num, gen, this.encryptionKey));
[40810] Fix | Delete
}
[40811] Fix | Delete
const key = this.#buildObjectKey(num, gen, this.encryptionKey, false);
[40812] Fix | Delete
const cipherConstructor = function () {
[40813] Fix | Delete
return new ARCFourCipher(key);
[40814] Fix | Delete
};
[40815] Fix | Delete
return new CipherTransform(cipherConstructor, cipherConstructor);
[40816] Fix | Delete
}
[40817] Fix | Delete
}
[40818] Fix | Delete
[40819] Fix | Delete
;// CONCATENATED MODULE: ./src/core/writer.js
[40820] Fix | Delete
[40821] Fix | Delete
[40822] Fix | Delete
[40823] Fix | Delete
[40824] Fix | Delete
[40825] Fix | Delete
[40826] Fix | Delete
[40827] Fix | Delete
[40828] Fix | Delete
[40829] Fix | Delete
[40830] Fix | Delete
[40831] Fix | Delete
[40832] Fix | Delete
[40833] Fix | Delete
[40834] Fix | Delete
[40835] Fix | Delete
[40836] Fix | Delete
[40837] Fix | Delete
async function writeObject(ref, obj, buffer, {
[40838] Fix | Delete
encrypt = null
[40839] Fix | Delete
}) {
[40840] Fix | Delete
const transform = encrypt?.createCipherTransform(ref.num, ref.gen);
[40841] Fix | Delete
buffer.push(`${ref.num} ${ref.gen} obj\n`);
[40842] Fix | Delete
if (obj instanceof Dict) {
[40843] Fix | Delete
await writeDict(obj, buffer, transform);
[40844] Fix | Delete
} else if (obj instanceof BaseStream) {
[40845] Fix | Delete
await writeStream(obj, buffer, transform);
[40846] Fix | Delete
} else if (Array.isArray(obj) || ArrayBuffer.isView(obj)) {
[40847] Fix | Delete
await writeArray(obj, buffer, transform);
[40848] Fix | Delete
}
[40849] Fix | Delete
buffer.push("\nendobj\n");
[40850] Fix | Delete
}
[40851] Fix | Delete
async function writeDict(dict, buffer, transform) {
[40852] Fix | Delete
buffer.push("<<");
[40853] Fix | Delete
for (const key of dict.getKeys()) {
[40854] Fix | Delete
buffer.push(` /${escapePDFName(key)} `);
[40855] Fix | Delete
await writeValue(dict.getRaw(key), buffer, transform);
[40856] Fix | Delete
}
[40857] Fix | Delete
buffer.push(">>");
[40858] Fix | Delete
}
[40859] Fix | Delete
async function writeStream(stream, buffer, transform) {
[40860] Fix | Delete
let bytes = stream.getBytes();
[40861] Fix | Delete
const {
[40862] Fix | Delete
dict
[40863] Fix | Delete
} = stream;
[40864] Fix | Delete
const [filter, params] = await Promise.all([dict.getAsync("Filter"), dict.getAsync("DecodeParms")]);
[40865] Fix | Delete
const filterZero = Array.isArray(filter) ? await dict.xref.fetchIfRefAsync(filter[0]) : filter;
[40866] Fix | Delete
const isFilterZeroFlateDecode = isName(filterZero, "FlateDecode");
[40867] Fix | Delete
const MIN_LENGTH_FOR_COMPRESSING = 256;
[40868] Fix | Delete
if (bytes.length >= MIN_LENGTH_FOR_COMPRESSING || isFilterZeroFlateDecode) {
[40869] Fix | Delete
try {
[40870] Fix | Delete
const cs = new CompressionStream("deflate");
[40871] Fix | Delete
const writer = cs.writable.getWriter();
[40872] Fix | Delete
writer.write(bytes);
[40873] Fix | Delete
writer.close();
[40874] Fix | Delete
const buf = await new Response(cs.readable).arrayBuffer();
[40875] Fix | Delete
bytes = new Uint8Array(buf);
[40876] Fix | Delete
let newFilter, newParams;
[40877] Fix | Delete
if (!filter) {
[40878] Fix | Delete
newFilter = Name.get("FlateDecode");
[40879] Fix | Delete
} else if (!isFilterZeroFlateDecode) {
[40880] Fix | Delete
newFilter = Array.isArray(filter) ? [Name.get("FlateDecode"), ...filter] : [Name.get("FlateDecode"), filter];
[40881] Fix | Delete
if (params) {
[40882] Fix | Delete
newParams = Array.isArray(params) ? [null, ...params] : [null, params];
[40883] Fix | Delete
}
[40884] Fix | Delete
}
[40885] Fix | Delete
if (newFilter) {
[40886] Fix | Delete
dict.set("Filter", newFilter);
[40887] Fix | Delete
}
[40888] Fix | Delete
if (newParams) {
[40889] Fix | Delete
dict.set("DecodeParms", newParams);
[40890] Fix | Delete
}
[40891] Fix | Delete
} catch (ex) {
[40892] Fix | Delete
info(`writeStream - cannot compress data: "${ex}".`);
[40893] Fix | Delete
}
[40894] Fix | Delete
}
[40895] Fix | Delete
let string = bytesToString(bytes);
[40896] Fix | Delete
if (transform) {
[40897] Fix | Delete
string = transform.encryptString(string);
[40898] Fix | Delete
}
[40899] Fix | Delete
dict.set("Length", string.length);
[40900] Fix | Delete
await writeDict(dict, buffer, transform);
[40901] Fix | Delete
buffer.push(" stream\n", string, "\nendstream");
[40902] Fix | Delete
}
[40903] Fix | Delete
async function writeArray(array, buffer, transform) {
[40904] Fix | Delete
buffer.push("[");
[40905] Fix | Delete
let first = true;
[40906] Fix | Delete
for (const val of array) {
[40907] Fix | Delete
if (!first) {
[40908] Fix | Delete
buffer.push(" ");
[40909] Fix | Delete
} else {
[40910] Fix | Delete
first = false;
[40911] Fix | Delete
}
[40912] Fix | Delete
await writeValue(val, buffer, transform);
[40913] Fix | Delete
}
[40914] Fix | Delete
buffer.push("]");
[40915] Fix | Delete
}
[40916] Fix | Delete
async function writeValue(value, buffer, transform) {
[40917] Fix | Delete
if (value instanceof Name) {
[40918] Fix | Delete
buffer.push(`/${escapePDFName(value.name)}`);
[40919] Fix | Delete
} else if (value instanceof Ref) {
[40920] Fix | Delete
buffer.push(`${value.num} ${value.gen} R`);
[40921] Fix | Delete
} else if (Array.isArray(value) || ArrayBuffer.isView(value)) {
[40922] Fix | Delete
await writeArray(value, buffer, transform);
[40923] Fix | Delete
} else if (typeof value === "string") {
[40924] Fix | Delete
if (transform) {
[40925] Fix | Delete
value = transform.encryptString(value);
[40926] Fix | Delete
}
[40927] Fix | Delete
buffer.push(`(${escapeString(value)})`);
[40928] Fix | Delete
} else if (typeof value === "number") {
[40929] Fix | Delete
buffer.push(numberToString(value));
[40930] Fix | Delete
} else if (typeof value === "boolean") {
[40931] Fix | Delete
buffer.push(value.toString());
[40932] Fix | Delete
} else if (value instanceof Dict) {
[40933] Fix | Delete
await writeDict(value, buffer, transform);
[40934] Fix | Delete
} else if (value instanceof BaseStream) {
[40935] Fix | Delete
await writeStream(value, buffer, transform);
[40936] Fix | Delete
} else if (value === null) {
[40937] Fix | Delete
buffer.push("null");
[40938] Fix | Delete
} else {
[40939] Fix | Delete
warn(`Unhandled value in writer: ${typeof value}, please file a bug.`);
[40940] Fix | Delete
}
[40941] Fix | Delete
}
[40942] Fix | Delete
function writeInt(number, size, offset, buffer) {
[40943] Fix | Delete
for (let i = size + offset - 1; i > offset - 1; i--) {
[40944] Fix | Delete
buffer[i] = number & 0xff;
[40945] Fix | Delete
number >>= 8;
[40946] Fix | Delete
}
[40947] Fix | Delete
return offset + size;
[40948] Fix | Delete
}
[40949] Fix | Delete
function writeString(string, offset, buffer) {
[40950] Fix | Delete
for (let i = 0, len = string.length; i < len; i++) {
[40951] Fix | Delete
buffer[offset + i] = string.charCodeAt(i) & 0xff;
[40952] Fix | Delete
}
[40953] Fix | Delete
}
[40954] Fix | Delete
function computeMD5(filesize, xrefInfo) {
[40955] Fix | Delete
const time = Math.floor(Date.now() / 1000);
[40956] Fix | Delete
const filename = xrefInfo.filename || "";
[40957] Fix | Delete
const md5Buffer = [time.toString(), filename, filesize.toString()];
[40958] Fix | Delete
let md5BufferLen = md5Buffer.reduce((a, str) => a + str.length, 0);
[40959] Fix | Delete
for (const value of Object.values(xrefInfo.info)) {
[40960] Fix | Delete
md5Buffer.push(value);
[40961] Fix | Delete
md5BufferLen += value.length;
[40962] Fix | Delete
}
[40963] Fix | Delete
const array = new Uint8Array(md5BufferLen);
[40964] Fix | Delete
let offset = 0;
[40965] Fix | Delete
for (const str of md5Buffer) {
[40966] Fix | Delete
writeString(str, offset, array);
[40967] Fix | Delete
offset += str.length;
[40968] Fix | Delete
}
[40969] Fix | Delete
return bytesToString(calculateMD5(array));
[40970] Fix | Delete
}
[40971] Fix | Delete
function writeXFADataForAcroform(str, newRefs) {
[40972] Fix | Delete
const xml = new SimpleXMLParser({
[40973] Fix | Delete
hasAttributes: true
[40974] Fix | Delete
}).parseFromString(str);
[40975] Fix | Delete
for (const {
[40976] Fix | Delete
xfa
[40977] Fix | Delete
} of newRefs) {
[40978] Fix | Delete
if (!xfa) {
[40979] Fix | Delete
continue;
[40980] Fix | Delete
}
[40981] Fix | Delete
const {
[40982] Fix | Delete
path,
[40983] Fix | Delete
value
[40984] Fix | Delete
} = xfa;
[40985] Fix | Delete
if (!path) {
[40986] Fix | Delete
continue;
[40987] Fix | Delete
}
[40988] Fix | Delete
const nodePath = parseXFAPath(path);
[40989] Fix | Delete
let node = xml.documentElement.searchNode(nodePath, 0);
[40990] Fix | Delete
if (!node && nodePath.length > 1) {
[40991] Fix | Delete
node = xml.documentElement.searchNode([nodePath.at(-1)], 0);
[40992] Fix | Delete
}
[40993] Fix | Delete
if (node) {
[40994] Fix | Delete
node.childNodes = Array.isArray(value) ? value.map(val => new SimpleDOMNode("value", val)) : [new SimpleDOMNode("#text", value)];
[40995] Fix | Delete
} else {
[40996] Fix | Delete
warn(`Node not found for path: ${path}`);
[40997] Fix | Delete
}
[40998] Fix | Delete
}
[40999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function