diff --git a/main.meta.js b/main.meta.js index 1a76d29..cdd8c07 100644 --- a/main.meta.js +++ b/main.meta.js @@ -1,7 +1,7 @@ // ==UserScript== // @name PNGExtraEmbed // @namespace https://coom.tech/ -// @version 0.123 +// @version 0.124 // @description uhh // @author You // @match https://boards.4channel.org/* diff --git a/main.user.js b/main.user.js index c47fb3e..60d64c6 100644 --- a/main.user.js +++ b/main.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @name PNGExtraEmbed // @namespace https://coom.tech/ -// @version 0.123 +// @version 0.124 // @description uhh // @author You // @match https://boards.4channel.org/* @@ -293,9 +293,9 @@ if (length > K_MAX_LENGTH) { throw new RangeError('The value "' + length + '" is invalid for option "size"'); } - const buf3 = new Uint8Array(length); - Object.setPrototypeOf(buf3, Buffer14.prototype); - return buf3; + const buf2 = new Uint8Array(length); + Object.setPrototypeOf(buf2, Buffer14.prototype); + return buf2; } function Buffer14(arg, encodingOrOffset, length) { if (typeof arg === "number") { @@ -381,20 +381,20 @@ throw new TypeError("Unknown encoding: " + encoding); } const length = byteLength(string, encoding) | 0; - let buf3 = createBuffer(length); - const actual = buf3.write(string, encoding); + let buf2 = createBuffer(length); + const actual = buf2.write(string, encoding); if (actual !== length) { - buf3 = buf3.slice(0, actual); + buf2 = buf2.slice(0, actual); } - return buf3; + return buf2; } function fromArrayLike(array) { const length = array.length < 0 ? 0 : checked(array.length) | 0; - const buf3 = createBuffer(length); + const buf2 = createBuffer(length); for (let i = 0; i < length; i += 1) { - buf3[i] = array[i] & 255; + buf2[i] = array[i] & 255; } - return buf3; + return buf2; } function fromArrayView(arrayView) { if (isInstance(arrayView, Uint8Array)) { @@ -410,26 +410,26 @@ if (array.byteLength < byteOffset + (length || 0)) { throw new RangeError('"length" is outside of buffer bounds'); } - let buf3; + let buf2; if (byteOffset === void 0 && length === void 0) { - buf3 = new Uint8Array(array); + buf2 = new Uint8Array(array); } else if (length === void 0) { - buf3 = new Uint8Array(array, byteOffset); + buf2 = new Uint8Array(array, byteOffset); } else { - buf3 = new Uint8Array(array, byteOffset, length); + buf2 = new Uint8Array(array, byteOffset, length); } - Object.setPrototypeOf(buf3, Buffer14.prototype); - return buf3; + Object.setPrototypeOf(buf2, Buffer14.prototype); + return buf2; } function fromObject(obj) { if (Buffer14.isBuffer(obj)) { const len = checked(obj.length) | 0; - const buf3 = createBuffer(len); - if (buf3.length === 0) { - return buf3; + const buf2 = createBuffer(len); + if (buf2.length === 0) { + return buf2; } - obj.copy(buf3, 0, 0, len); - return buf3; + obj.copy(buf2, 0, 0, len); + return buf2; } if (obj.length !== void 0) { if (typeof obj.length !== "number" || numberIsNaN(obj.length)) { @@ -516,21 +516,21 @@ const buffer = Buffer14.allocUnsafe(length); let pos = 0; for (i = 0; i < list.length; ++i) { - let buf3 = list[i]; - if (isInstance(buf3, Uint8Array)) { - if (pos + buf3.length > buffer.length) { - if (!Buffer14.isBuffer(buf3)) - buf3 = Buffer14.from(buf3); - buf3.copy(buffer, pos); + let buf2 = list[i]; + if (isInstance(buf2, Uint8Array)) { + if (pos + buf2.length > buffer.length) { + if (!Buffer14.isBuffer(buf2)) + buf2 = Buffer14.from(buf2); + buf2.copy(buffer, pos); } else { - Uint8Array.prototype.set.call(buffer, buf3, pos); + Uint8Array.prototype.set.call(buffer, buf2, pos); } - } else if (!Buffer14.isBuffer(buf3)) { + } else if (!Buffer14.isBuffer(buf2)) { throw new TypeError('"list" argument must be an Array of Buffers'); } else { - buf3.copy(buffer, pos); + buf2.copy(buffer, pos); } - pos += buf3.length; + pos += buf2.length; } return buffer; }; @@ -812,11 +812,11 @@ byteOffset /= 2; } } - function read2(buf3, i2) { + function read2(buf2, i2) { if (indexSize === 1) { - return buf3[i2]; + return buf2[i2]; } else { - return buf3.readUInt16BE(i2 * indexSize); + return buf2.readUInt16BE(i2 * indexSize); } } let i; @@ -860,9 +860,9 @@ Buffer14.prototype.lastIndexOf = function lastIndexOf(val, byteOffset, encoding) { return bidirectionalIndexOf(this, val, byteOffset, encoding, false); }; - function hexWrite(buf3, string, offset, length) { + function hexWrite(buf2, string, offset, length) { offset = Number(offset) || 0; - const remaining = buf3.length - offset; + const remaining = buf2.length - offset; if (!length) { length = remaining; } else { @@ -880,21 +880,21 @@ const parsed = parseInt(string.substr(i * 2, 2), 16); if (numberIsNaN(parsed)) return i; - buf3[offset + i] = parsed; + buf2[offset + i] = parsed; } return i; } - function utf8Write(buf3, string, offset, length) { - return blitBuffer(utf8ToBytes(string, buf3.length - offset), buf3, offset, length); + function utf8Write(buf2, string, offset, length) { + return blitBuffer(utf8ToBytes(string, buf2.length - offset), buf2, offset, length); } - function asciiWrite(buf3, string, offset, length) { - return blitBuffer(asciiToBytes(string), buf3, offset, length); + function asciiWrite(buf2, string, offset, length) { + return blitBuffer(asciiToBytes(string), buf2, offset, length); } - function base64Write(buf3, string, offset, length) { - return blitBuffer(base64ToBytes(string), buf3, offset, length); + function base64Write(buf2, string, offset, length) { + return blitBuffer(base64ToBytes(string), buf2, offset, length); } - function ucs2Write(buf3, string, offset, length) { - return blitBuffer(utf16leToBytes(string, buf3.length - offset), buf3, offset, length); + function ucs2Write(buf2, string, offset, length) { + return blitBuffer(utf16leToBytes(string, buf2.length - offset), buf2, offset, length); } Buffer14.prototype.write = function write2(string, offset, length, encoding) { if (offset === void 0) { @@ -959,19 +959,19 @@ data: Array.prototype.slice.call(this._arr || this, 0) }; }; - function base64Slice(buf3, start, end) { - if (start === 0 && end === buf3.length) { - return base64.fromByteArray(buf3); + function base64Slice(buf2, start, end) { + if (start === 0 && end === buf2.length) { + return base64.fromByteArray(buf2); } else { - return base64.fromByteArray(buf3.slice(start, end)); + return base64.fromByteArray(buf2.slice(start, end)); } } - function utf8Slice(buf3, start, end) { - end = Math.min(buf3.length, end); + function utf8Slice(buf2, start, end) { + end = Math.min(buf2.length, end); const res = []; let i = start; while (i < end) { - const firstByte = buf3[i]; + const firstByte = buf2[i]; let codePoint = null; let bytesPerSequence = firstByte > 239 ? 4 : firstByte > 223 ? 3 : firstByte > 191 ? 2 : 1; if (i + bytesPerSequence <= end) { @@ -983,7 +983,7 @@ } break; case 2: - secondByte = buf3[i + 1]; + secondByte = buf2[i + 1]; if ((secondByte & 192) === 128) { tempCodePoint = (firstByte & 31) << 6 | secondByte & 63; if (tempCodePoint > 127) { @@ -992,8 +992,8 @@ } break; case 3: - secondByte = buf3[i + 1]; - thirdByte = buf3[i + 2]; + secondByte = buf2[i + 1]; + thirdByte = buf2[i + 2]; if ((secondByte & 192) === 128 && (thirdByte & 192) === 128) { tempCodePoint = (firstByte & 15) << 12 | (secondByte & 63) << 6 | thirdByte & 63; if (tempCodePoint > 2047 && (tempCodePoint < 55296 || tempCodePoint > 57343)) { @@ -1002,9 +1002,9 @@ } break; case 4: - secondByte = buf3[i + 1]; - thirdByte = buf3[i + 2]; - fourthByte = buf3[i + 3]; + secondByte = buf2[i + 1]; + thirdByte = buf2[i + 2]; + fourthByte = buf2[i + 3]; if ((secondByte & 192) === 128 && (thirdByte & 192) === 128 && (fourthByte & 192) === 128) { tempCodePoint = (firstByte & 15) << 18 | (secondByte & 63) << 12 | (thirdByte & 63) << 6 | fourthByte & 63; if (tempCodePoint > 65535 && tempCodePoint < 1114112) { @@ -1039,36 +1039,36 @@ } return res; } - function asciiSlice(buf3, start, end) { + function asciiSlice(buf2, start, end) { let ret = ""; - end = Math.min(buf3.length, end); + end = Math.min(buf2.length, end); for (let i = start; i < end; ++i) { - ret += String.fromCharCode(buf3[i] & 127); + ret += String.fromCharCode(buf2[i] & 127); } return ret; } - function latin1Slice(buf3, start, end) { + function latin1Slice(buf2, start, end) { let ret = ""; - end = Math.min(buf3.length, end); + end = Math.min(buf2.length, end); for (let i = start; i < end; ++i) { - ret += String.fromCharCode(buf3[i]); + ret += String.fromCharCode(buf2[i]); } return ret; } - function hexSlice(buf3, start, end) { - const len = buf3.length; + function hexSlice(buf2, start, end) { + const len = buf2.length; if (!start || start < 0) start = 0; if (!end || end < 0 || end > len) end = len; let out = ""; for (let i = start; i < end; ++i) { - out += hexSliceLookupTable[buf3[i]]; + out += hexSliceLookupTable[buf2[i]]; } return out; } - function utf16leSlice(buf3, start, end) { - const bytes = buf3.slice(start, end); + function utf16leSlice(buf2, start, end) { + const bytes = buf2.slice(start, end); let res = ""; for (let i = 0; i < bytes.length - 1; i += 2) { res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256); @@ -1297,12 +1297,12 @@ checkOffset(offset, 8, this.length); return ieee7542.read(this, offset, false, 52, 8); }; - function checkInt(buf3, value, offset, ext, max, min) { - if (!Buffer14.isBuffer(buf3)) + function checkInt(buf2, value, offset, ext, max, min) { + if (!Buffer14.isBuffer(buf2)) throw new TypeError('"buffer" argument must be a Buffer instance'); if (value > max || value < min) throw new RangeError('"value" argument is out of bounds'); - if (offset + ext > buf3.length) + if (offset + ext > buf2.length) throw new RangeError("Index out of range"); } Buffer14.prototype.writeUintLE = Buffer14.prototype.writeUIntLE = function writeUIntLE(value, offset, byteLength2, noAssert) { @@ -1385,44 +1385,44 @@ this[offset + 3] = value & 255; return offset + 4; }; - function wrtBigUInt64LE(buf3, value, offset, min, max) { - checkIntBI(value, min, max, buf3, offset, 7); + function wrtBigUInt64LE(buf2, value, offset, min, max) { + checkIntBI(value, min, max, buf2, offset, 7); let lo = Number(value & BigInt(4294967295)); - buf3[offset++] = lo; + buf2[offset++] = lo; lo = lo >> 8; - buf3[offset++] = lo; + buf2[offset++] = lo; lo = lo >> 8; - buf3[offset++] = lo; + buf2[offset++] = lo; lo = lo >> 8; - buf3[offset++] = lo; + buf2[offset++] = lo; let hi = Number(value >> BigInt(32) & BigInt(4294967295)); - buf3[offset++] = hi; + buf2[offset++] = hi; hi = hi >> 8; - buf3[offset++] = hi; + buf2[offset++] = hi; hi = hi >> 8; - buf3[offset++] = hi; + buf2[offset++] = hi; hi = hi >> 8; - buf3[offset++] = hi; + buf2[offset++] = hi; return offset; } - function wrtBigUInt64BE(buf3, value, offset, min, max) { - checkIntBI(value, min, max, buf3, offset, 7); + function wrtBigUInt64BE(buf2, value, offset, min, max) { + checkIntBI(value, min, max, buf2, offset, 7); let lo = Number(value & BigInt(4294967295)); - buf3[offset + 7] = lo; + buf2[offset + 7] = lo; lo = lo >> 8; - buf3[offset + 6] = lo; + buf2[offset + 6] = lo; lo = lo >> 8; - buf3[offset + 5] = lo; + buf2[offset + 5] = lo; lo = lo >> 8; - buf3[offset + 4] = lo; + buf2[offset + 4] = lo; let hi = Number(value >> BigInt(32) & BigInt(4294967295)); - buf3[offset + 3] = hi; + buf2[offset + 3] = hi; hi = hi >> 8; - buf3[offset + 2] = hi; + buf2[offset + 2] = hi; hi = hi >> 8; - buf3[offset + 1] = hi; + buf2[offset + 1] = hi; hi = hi >> 8; - buf3[offset] = hi; + buf2[offset] = hi; return offset + 8; } Buffer14.prototype.writeBigUInt64LE = defineBigIntMethod(function writeBigUInt64LE(value, offset = 0) { @@ -1527,19 +1527,19 @@ Buffer14.prototype.writeBigInt64BE = defineBigIntMethod(function writeBigInt64BE(value, offset = 0) { return wrtBigUInt64BE(this, value, offset, -BigInt("0x8000000000000000"), BigInt("0x7fffffffffffffff")); }); - function checkIEEE754(buf3, value, offset, ext, max, min) { - if (offset + ext > buf3.length) + function checkIEEE754(buf2, value, offset, ext, max, min) { + if (offset + ext > buf2.length) throw new RangeError("Index out of range"); if (offset < 0) throw new RangeError("Index out of range"); } - function writeFloat(buf3, value, offset, littleEndian, noAssert) { + function writeFloat(buf2, value, offset, littleEndian, noAssert) { value = +value; offset = offset >>> 0; if (!noAssert) { - checkIEEE754(buf3, value, offset, 4, 34028234663852886e22, -34028234663852886e22); + checkIEEE754(buf2, value, offset, 4, 34028234663852886e22, -34028234663852886e22); } - ieee7542.write(buf3, value, offset, littleEndian, 23, 4); + ieee7542.write(buf2, value, offset, littleEndian, 23, 4); return offset + 4; } Buffer14.prototype.writeFloatLE = function writeFloatLE(value, offset, noAssert) { @@ -1548,13 +1548,13 @@ Buffer14.prototype.writeFloatBE = function writeFloatBE(value, offset, noAssert) { return writeFloat(this, value, offset, false, noAssert); }; - function writeDouble(buf3, value, offset, littleEndian, noAssert) { + function writeDouble(buf2, value, offset, littleEndian, noAssert) { value = +value; offset = offset >>> 0; if (!noAssert) { - checkIEEE754(buf3, value, offset, 8, 17976931348623157e292, -17976931348623157e292); + checkIEEE754(buf2, value, offset, 8, 17976931348623157e292, -17976931348623157e292); } - ieee7542.write(buf3, value, offset, littleEndian, 52, 8); + ieee7542.write(buf2, value, offset, littleEndian, 52, 8); return offset + 8; } Buffer14.prototype.writeDoubleLE = function writeDoubleLE(value, offset, noAssert) { @@ -1717,13 +1717,13 @@ } return `${val.slice(0, i)}${res}`; } - function checkBounds(buf3, offset, byteLength2) { + function checkBounds(buf2, offset, byteLength2) { validateNumber(offset, "offset"); - if (buf3[offset] === void 0 || buf3[offset + byteLength2] === void 0) { - boundsError(offset, buf3.length - (byteLength2 + 1)); + if (buf2[offset] === void 0 || buf2[offset + byteLength2] === void 0) { + boundsError(offset, buf2.length - (byteLength2 + 1)); } } - function checkIntBI(value, min, max, buf3, offset, byteLength2) { + function checkIntBI(value, min, max, buf2, offset, byteLength2) { if (value > max || value < min) { const n = typeof min === "bigint" ? "n" : ""; let range; @@ -1738,7 +1738,7 @@ } throw new errors.ERR_OUT_OF_RANGE("value", range, value); } - checkBounds(buf3, offset, byteLength2); + checkBounds(buf2, offset, byteLength2); } function validateNumber(value, name) { if (typeof value !== "number") { @@ -1939,34 +1939,34 @@ C = C >>> 8 ^ T[(C ^ bstr.charCodeAt(i)) & 255]; return C ^ -1; } - function crc32_buf(buf3, seed) { - if (buf3.length > 1e4) - return crc32_buf_8(buf3, seed); - var C = seed ^ -1, L = buf3.length - 3; + function crc32_buf(buf2, seed) { + if (buf2.length > 1e4) + return crc32_buf_8(buf2, seed); + var C = seed ^ -1, L = buf2.length - 3; for (var i = 0; i < L; ) { - C = C >>> 8 ^ T[(C ^ buf3[i++]) & 255]; - C = C >>> 8 ^ T[(C ^ buf3[i++]) & 255]; - C = C >>> 8 ^ T[(C ^ buf3[i++]) & 255]; - C = C >>> 8 ^ T[(C ^ buf3[i++]) & 255]; + C = C >>> 8 ^ T[(C ^ buf2[i++]) & 255]; + C = C >>> 8 ^ T[(C ^ buf2[i++]) & 255]; + C = C >>> 8 ^ T[(C ^ buf2[i++]) & 255]; + C = C >>> 8 ^ T[(C ^ buf2[i++]) & 255]; } while (i < L + 3) - C = C >>> 8 ^ T[(C ^ buf3[i++]) & 255]; + C = C >>> 8 ^ T[(C ^ buf2[i++]) & 255]; return C ^ -1; } - function crc32_buf_8(buf3, seed) { - var C = seed ^ -1, L = buf3.length - 7; + function crc32_buf_8(buf2, seed) { + var C = seed ^ -1, L = buf2.length - 7; for (var i = 0; i < L; ) { - C = C >>> 8 ^ T[(C ^ buf3[i++]) & 255]; - C = C >>> 8 ^ T[(C ^ buf3[i++]) & 255]; - C = C >>> 8 ^ T[(C ^ buf3[i++]) & 255]; - C = C >>> 8 ^ T[(C ^ buf3[i++]) & 255]; - C = C >>> 8 ^ T[(C ^ buf3[i++]) & 255]; - C = C >>> 8 ^ T[(C ^ buf3[i++]) & 255]; - C = C >>> 8 ^ T[(C ^ buf3[i++]) & 255]; - C = C >>> 8 ^ T[(C ^ buf3[i++]) & 255]; + C = C >>> 8 ^ T[(C ^ buf2[i++]) & 255]; + C = C >>> 8 ^ T[(C ^ buf2[i++]) & 255]; + C = C >>> 8 ^ T[(C ^ buf2[i++]) & 255]; + C = C >>> 8 ^ T[(C ^ buf2[i++]) & 255]; + C = C >>> 8 ^ T[(C ^ buf2[i++]) & 255]; + C = C >>> 8 ^ T[(C ^ buf2[i++]) & 255]; + C = C >>> 8 ^ T[(C ^ buf2[i++]) & 255]; + C = C >>> 8 ^ T[(C ^ buf2[i++]) & 255]; } while (i < L + 7) - C = C >>> 8 ^ T[(C ^ buf3[i++]) & 255]; + C = C >>> 8 ^ T[(C ^ buf2[i++]) & 255]; return C ^ -1; } function crc32_str(str, seed) { @@ -4483,9 +4483,9 @@ if (length > K_MAX_LENGTH) { throw new RangeError('The value "' + length + '" is invalid for option "size"'); } - var buf3 = new Uint8Array(length); - Object.setPrototypeOf(buf3, Buffer14.prototype); - return buf3; + var buf2 = new Uint8Array(length); + Object.setPrototypeOf(buf2, Buffer14.prototype); + return buf2; } function Buffer14(arg, encodingOrOffset, length) { if (typeof arg === "number") { @@ -4571,20 +4571,20 @@ throw new TypeError("Unknown encoding: " + encoding); } var length = byteLength(string, encoding) | 0; - var buf3 = createBuffer(length); - var actual = buf3.write(string, encoding); + var buf2 = createBuffer(length); + var actual = buf2.write(string, encoding); if (actual !== length) { - buf3 = buf3.slice(0, actual); + buf2 = buf2.slice(0, actual); } - return buf3; + return buf2; } function fromArrayLike(array) { var length = array.length < 0 ? 0 : checked(array.length) | 0; - var buf3 = createBuffer(length); + var buf2 = createBuffer(length); for (var i = 0; i < length; i += 1) { - buf3[i] = array[i] & 255; + buf2[i] = array[i] & 255; } - return buf3; + return buf2; } function fromArrayView(arrayView) { if (isInstance(arrayView, Uint8Array)) { @@ -4600,26 +4600,26 @@ if (array.byteLength < byteOffset + (length || 0)) { throw new RangeError('"length" is outside of buffer bounds'); } - var buf3; + var buf2; if (byteOffset === void 0 && length === void 0) { - buf3 = new Uint8Array(array); + buf2 = new Uint8Array(array); } else if (length === void 0) { - buf3 = new Uint8Array(array, byteOffset); + buf2 = new Uint8Array(array, byteOffset); } else { - buf3 = new Uint8Array(array, byteOffset, length); + buf2 = new Uint8Array(array, byteOffset, length); } - Object.setPrototypeOf(buf3, Buffer14.prototype); - return buf3; + Object.setPrototypeOf(buf2, Buffer14.prototype); + return buf2; } function fromObject(obj) { if (Buffer14.isBuffer(obj)) { var len = checked(obj.length) | 0; - var buf3 = createBuffer(len); - if (buf3.length === 0) { - return buf3; + var buf2 = createBuffer(len); + if (buf2.length === 0) { + return buf2; } - obj.copy(buf3, 0, 0, len); - return buf3; + obj.copy(buf2, 0, 0, len); + return buf2; } if (obj.length !== void 0) { if (typeof obj.length !== "number" || numberIsNaN(obj.length)) { @@ -4706,19 +4706,19 @@ var buffer = Buffer14.allocUnsafe(length); var pos = 0; for (i = 0; i < list.length; ++i) { - var buf3 = list[i]; - if (isInstance(buf3, Uint8Array)) { - if (pos + buf3.length > buffer.length) { - Buffer14.from(buf3).copy(buffer, pos); + var buf2 = list[i]; + if (isInstance(buf2, Uint8Array)) { + if (pos + buf2.length > buffer.length) { + Buffer14.from(buf2).copy(buffer, pos); } else { - Uint8Array.prototype.set.call(buffer, buf3, pos); + Uint8Array.prototype.set.call(buffer, buf2, pos); } - } else if (!Buffer14.isBuffer(buf3)) { + } else if (!Buffer14.isBuffer(buf2)) { throw new TypeError('"list" argument must be an Array of Buffers'); } else { - buf3.copy(buffer, pos); + buf2.copy(buffer, pos); } - pos += buf3.length; + pos += buf2.length; } return buffer; }; @@ -5000,11 +5000,11 @@ byteOffset /= 2; } } - function read2(buf3, i2) { + function read2(buf2, i2) { if (indexSize === 1) { - return buf3[i2]; + return buf2[i2]; } else { - return buf3.readUInt16BE(i2 * indexSize); + return buf2.readUInt16BE(i2 * indexSize); } } var i; @@ -5048,9 +5048,9 @@ Buffer14.prototype.lastIndexOf = function lastIndexOf(val, byteOffset, encoding) { return bidirectionalIndexOf(this, val, byteOffset, encoding, false); }; - function hexWrite(buf3, string, offset, length) { + function hexWrite(buf2, string, offset, length) { offset = Number(offset) || 0; - var remaining = buf3.length - offset; + var remaining = buf2.length - offset; if (!length) { length = remaining; } else { @@ -5067,21 +5067,21 @@ var parsed = parseInt(string.substr(i * 2, 2), 16); if (numberIsNaN(parsed)) return i; - buf3[offset + i] = parsed; + buf2[offset + i] = parsed; } return i; } - function utf8Write(buf3, string, offset, length) { - return blitBuffer(utf8ToBytes(string, buf3.length - offset), buf3, offset, length); + function utf8Write(buf2, string, offset, length) { + return blitBuffer(utf8ToBytes(string, buf2.length - offset), buf2, offset, length); } - function asciiWrite(buf3, string, offset, length) { - return blitBuffer(asciiToBytes(string), buf3, offset, length); + function asciiWrite(buf2, string, offset, length) { + return blitBuffer(asciiToBytes(string), buf2, offset, length); } - function base64Write(buf3, string, offset, length) { - return blitBuffer(base64ToBytes(string), buf3, offset, length); + function base64Write(buf2, string, offset, length) { + return blitBuffer(base64ToBytes(string), buf2, offset, length); } - function ucs2Write(buf3, string, offset, length) { - return blitBuffer(utf16leToBytes(string, buf3.length - offset), buf3, offset, length); + function ucs2Write(buf2, string, offset, length) { + return blitBuffer(utf16leToBytes(string, buf2.length - offset), buf2, offset, length); } Buffer14.prototype.write = function write2(string, offset, length, encoding) { if (offset === void 0) { @@ -5146,19 +5146,19 @@ data: Array.prototype.slice.call(this._arr || this, 0) }; }; - function base64Slice(buf3, start, end) { - if (start === 0 && end === buf3.length) { - return base64.fromByteArray(buf3); + function base64Slice(buf2, start, end) { + if (start === 0 && end === buf2.length) { + return base64.fromByteArray(buf2); } else { - return base64.fromByteArray(buf3.slice(start, end)); + return base64.fromByteArray(buf2.slice(start, end)); } } - function utf8Slice(buf3, start, end) { - end = Math.min(buf3.length, end); + function utf8Slice(buf2, start, end) { + end = Math.min(buf2.length, end); var res = []; var i = start; while (i < end) { - var firstByte = buf3[i]; + var firstByte = buf2[i]; var codePoint = null; var bytesPerSequence = firstByte > 239 ? 4 : firstByte > 223 ? 3 : firstByte > 191 ? 2 : 1; if (i + bytesPerSequence <= end) { @@ -5170,7 +5170,7 @@ } break; case 2: - secondByte = buf3[i + 1]; + secondByte = buf2[i + 1]; if ((secondByte & 192) === 128) { tempCodePoint = (firstByte & 31) << 6 | secondByte & 63; if (tempCodePoint > 127) { @@ -5179,8 +5179,8 @@ } break; case 3: - secondByte = buf3[i + 1]; - thirdByte = buf3[i + 2]; + secondByte = buf2[i + 1]; + thirdByte = buf2[i + 2]; if ((secondByte & 192) === 128 && (thirdByte & 192) === 128) { tempCodePoint = (firstByte & 15) << 12 | (secondByte & 63) << 6 | thirdByte & 63; if (tempCodePoint > 2047 && (tempCodePoint < 55296 || tempCodePoint > 57343)) { @@ -5189,9 +5189,9 @@ } break; case 4: - secondByte = buf3[i + 1]; - thirdByte = buf3[i + 2]; - fourthByte = buf3[i + 3]; + secondByte = buf2[i + 1]; + thirdByte = buf2[i + 2]; + fourthByte = buf2[i + 3]; if ((secondByte & 192) === 128 && (thirdByte & 192) === 128 && (fourthByte & 192) === 128) { tempCodePoint = (firstByte & 15) << 18 | (secondByte & 63) << 12 | (thirdByte & 63) << 6 | fourthByte & 63; if (tempCodePoint > 65535 && tempCodePoint < 1114112) { @@ -5226,36 +5226,36 @@ } return res; } - function asciiSlice(buf3, start, end) { + function asciiSlice(buf2, start, end) { var ret = ""; - end = Math.min(buf3.length, end); + end = Math.min(buf2.length, end); for (var i = start; i < end; ++i) { - ret += String.fromCharCode(buf3[i] & 127); + ret += String.fromCharCode(buf2[i] & 127); } return ret; } - function latin1Slice(buf3, start, end) { + function latin1Slice(buf2, start, end) { var ret = ""; - end = Math.min(buf3.length, end); + end = Math.min(buf2.length, end); for (var i = start; i < end; ++i) { - ret += String.fromCharCode(buf3[i]); + ret += String.fromCharCode(buf2[i]); } return ret; } - function hexSlice(buf3, start, end) { - var len = buf3.length; + function hexSlice(buf2, start, end) { + var len = buf2.length; if (!start || start < 0) start = 0; if (!end || end < 0 || end > len) end = len; var out = ""; for (var i = start; i < end; ++i) { - out += hexSliceLookupTable[buf3[i]]; + out += hexSliceLookupTable[buf2[i]]; } return out; } - function utf16leSlice(buf3, start, end) { - var bytes = buf3.slice(start, end); + function utf16leSlice(buf2, start, end) { + var bytes = buf2.slice(start, end); var res = ""; for (var i = 0; i < bytes.length - 1; i += 2) { res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256); @@ -5438,12 +5438,12 @@ checkOffset(offset, 8, this.length); return ieee7542.read(this, offset, false, 52, 8); }; - function checkInt(buf3, value, offset, ext, max, min) { - if (!Buffer14.isBuffer(buf3)) + function checkInt(buf2, value, offset, ext, max, min) { + if (!Buffer14.isBuffer(buf2)) throw new TypeError('"buffer" argument must be a Buffer instance'); if (value > max || value < min) throw new RangeError('"value" argument is out of bounds'); - if (offset + ext > buf3.length) + if (offset + ext > buf2.length) throw new RangeError("Index out of range"); } Buffer14.prototype.writeUintLE = Buffer14.prototype.writeUIntLE = function writeUIntLE(value, offset, byteLength2, noAssert) { @@ -5616,19 +5616,19 @@ this[offset + 3] = value & 255; return offset + 4; }; - function checkIEEE754(buf3, value, offset, ext, max, min) { - if (offset + ext > buf3.length) + function checkIEEE754(buf2, value, offset, ext, max, min) { + if (offset + ext > buf2.length) throw new RangeError("Index out of range"); if (offset < 0) throw new RangeError("Index out of range"); } - function writeFloat(buf3, value, offset, littleEndian, noAssert) { + function writeFloat(buf2, value, offset, littleEndian, noAssert) { value = +value; offset = offset >>> 0; if (!noAssert) { - checkIEEE754(buf3, value, offset, 4, 34028234663852886e22, -34028234663852886e22); + checkIEEE754(buf2, value, offset, 4, 34028234663852886e22, -34028234663852886e22); } - ieee7542.write(buf3, value, offset, littleEndian, 23, 4); + ieee7542.write(buf2, value, offset, littleEndian, 23, 4); return offset + 4; } Buffer14.prototype.writeFloatLE = function writeFloatLE(value, offset, noAssert) { @@ -5637,13 +5637,13 @@ Buffer14.prototype.writeFloatBE = function writeFloatBE(value, offset, noAssert) { return writeFloat(this, value, offset, false, noAssert); }; - function writeDouble(buf3, value, offset, littleEndian, noAssert) { + function writeDouble(buf2, value, offset, littleEndian, noAssert) { value = +value; offset = offset >>> 0; if (!noAssert) { - checkIEEE754(buf3, value, offset, 8, 17976931348623157e292, -17976931348623157e292); + checkIEEE754(buf2, value, offset, 8, 17976931348623157e292, -17976931348623157e292); } - ieee7542.write(buf3, value, offset, littleEndian, 52, 8); + ieee7542.write(buf2, value, offset, littleEndian, 52, 8); return offset + 8; } Buffer14.prototype.writeDoubleLE = function writeDoubleLE(value, offset, noAssert) { @@ -6086,8 +6086,8 @@ exports.readVint = _tools.readVint; exports.writeVint = _tools.writeVint; exports.ebmlBlock = _block; - function readBlock(buf3) { - return exports.ebmlBlock(new exports.Buffer(buf3)); + function readBlock(buf2) { + return exports.ebmlBlock(new exports.Buffer(buf2)); } exports.readBlock = readBlock; function encodeTag(tagId, tagData, unknownSize) { @@ -6332,8 +6332,8 @@ var encorder = new EBMLEncoder_1.default(); return refinedMetaData.reduce(function(lst, elm) { return lst.concat(encorder.encode([elm])); - }, []).reduce(function(o, buf3) { - return o + buf3.byteLength; + }, []).reduce(function(o, buf2) { + return o + buf2.byteLength; }, 0); } function refineMetadata(mesetadata, sizeDiff, info) { @@ -6421,9 +6421,9 @@ var buffer = exports.Buffer.allocUnsafe(length); var pos = 0; for (i = 0; i < list.length; ++i) { - var buf3 = list[i]; - buf3.copy(buffer, pos); - pos += buf3.length; + var buf2 = list[i]; + buf2.copy(buffer, pos); + pos += buf2.length; } return buffer; } @@ -6575,8 +6575,8 @@ if (tag == null) { return false; } - var buf3 = this._buffer.slice(this._cursor, this._cursor + tag.length); - var tagNum = buf3.reduce(function(o, v, i, arr) { + var buf2 = this._buffer.slice(this._cursor, this._cursor + tag.length); + var tagNum = buf2.reduce(function(o, v, i, arr) { return o + v * Math.pow(16, 2 * (arr.length - 1 - i)); }, 0); var schema2 = this.getSchemaInfo(tagNum); @@ -7890,12 +7890,12 @@ p.data.copy(ret); n -= p.data.length; while (p = p.next) { - var buf3 = p.data; - var nb = n > buf3.length ? buf3.length : n; - buf3.copy(ret, ret.length - n, 0, nb); + var buf2 = p.data; + var nb = n > buf2.length ? buf2.length : n; + buf2.copy(ret, ret.length - n, 0, nb); n -= nb; if (n === 0) { - if (nb === buf3.length) { + if (nb === buf2.length) { ++c; if (p.next) this.head = p.next; @@ -7903,7 +7903,7 @@ this.head = this.tail = null; } else { this.head = p; - p.data = buf3.slice(nb); + p.data = buf2.slice(nb); } break; } @@ -8839,17 +8839,17 @@ if (typeof size !== "number") { throw new TypeError("Argument must be a number"); } - var buf3 = Buffer14(size); + var buf2 = Buffer14(size); if (fill !== void 0) { if (typeof encoding === "string") { - buf3.fill(fill, encoding); + buf2.fill(fill, encoding); } else { - buf3.fill(fill); + buf2.fill(fill); } } else { - buf3.fill(0); + buf2.fill(0); } - return buf3; + return buf2; }; SafeBuffer.allocUnsafe = function(size) { if (typeof size !== "number") { @@ -8954,13 +8954,13 @@ this.lastTotal = 0; this.lastChar = Buffer14.allocUnsafe(nb); } - StringDecoder.prototype.write = function(buf3) { - if (buf3.length === 0) + StringDecoder.prototype.write = function(buf2) { + if (buf2.length === 0) return ""; var r; var i; if (this.lastNeed) { - r = this.fillLast(buf3); + r = this.fillLast(buf2); if (r === void 0) return ""; i = this.lastNeed; @@ -8968,19 +8968,19 @@ } else { i = 0; } - if (i < buf3.length) - return r ? r + this.text(buf3, i) : this.text(buf3, i); + if (i < buf2.length) + return r ? r + this.text(buf2, i) : this.text(buf2, i); return r || ""; }; StringDecoder.prototype.end = utf8End; StringDecoder.prototype.text = utf8Text; - StringDecoder.prototype.fillLast = function(buf3) { - if (this.lastNeed <= buf3.length) { - buf3.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, this.lastNeed); + StringDecoder.prototype.fillLast = function(buf2) { + if (this.lastNeed <= buf2.length) { + buf2.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, this.lastNeed); return this.lastChar.toString(this.encoding, 0, this.lastTotal); } - buf3.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, buf3.length); - this.lastNeed -= buf3.length; + buf2.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, buf2.length); + this.lastNeed -= buf2.length; }; function utf8CheckByte(byte) { if (byte <= 127) @@ -8993,11 +8993,11 @@ return 4; return byte >> 6 === 2 ? -1 : -2; } - function utf8CheckIncomplete(self, buf3, i) { - var j = buf3.length - 1; + function utf8CheckIncomplete(self, buf2, i) { + var j = buf2.length - 1; if (j < i) return 0; - var nb = utf8CheckByte(buf3[j]); + var nb = utf8CheckByte(buf2[j]); if (nb >= 0) { if (nb > 0) self.lastNeed = nb - 1; @@ -9005,7 +9005,7 @@ } if (--j < i || nb === -2) return 0; - nb = utf8CheckByte(buf3[j]); + nb = utf8CheckByte(buf2[j]); if (nb >= 0) { if (nb > 0) self.lastNeed = nb - 2; @@ -9013,7 +9013,7 @@ } if (--j < i || nb === -2) return 0; - nb = utf8CheckByte(buf3[j]); + nb = utf8CheckByte(buf2[j]); if (nb >= 0) { if (nb > 0) { if (nb === 2) @@ -9025,61 +9025,61 @@ } return 0; } - function utf8CheckExtraBytes(self, buf3, p) { - if ((buf3[0] & 192) !== 128) { + function utf8CheckExtraBytes(self, buf2, p) { + if ((buf2[0] & 192) !== 128) { self.lastNeed = 0; return "\uFFFD"; } - if (self.lastNeed > 1 && buf3.length > 1) { - if ((buf3[1] & 192) !== 128) { + if (self.lastNeed > 1 && buf2.length > 1) { + if ((buf2[1] & 192) !== 128) { self.lastNeed = 1; return "\uFFFD"; } - if (self.lastNeed > 2 && buf3.length > 2) { - if ((buf3[2] & 192) !== 128) { + if (self.lastNeed > 2 && buf2.length > 2) { + if ((buf2[2] & 192) !== 128) { self.lastNeed = 2; return "\uFFFD"; } } } } - function utf8FillLast(buf3) { + function utf8FillLast(buf2) { var p = this.lastTotal - this.lastNeed; - var r = utf8CheckExtraBytes(this, buf3, p); + var r = utf8CheckExtraBytes(this, buf2, p); if (r !== void 0) return r; - if (this.lastNeed <= buf3.length) { - buf3.copy(this.lastChar, p, 0, this.lastNeed); + if (this.lastNeed <= buf2.length) { + buf2.copy(this.lastChar, p, 0, this.lastNeed); return this.lastChar.toString(this.encoding, 0, this.lastTotal); } - buf3.copy(this.lastChar, p, 0, buf3.length); - this.lastNeed -= buf3.length; + buf2.copy(this.lastChar, p, 0, buf2.length); + this.lastNeed -= buf2.length; } - function utf8Text(buf3, i) { - var total = utf8CheckIncomplete(this, buf3, i); + function utf8Text(buf2, i) { + var total = utf8CheckIncomplete(this, buf2, i); if (!this.lastNeed) - return buf3.toString("utf8", i); + return buf2.toString("utf8", i); this.lastTotal = total; - var end = buf3.length - (total - this.lastNeed); - buf3.copy(this.lastChar, 0, end); - return buf3.toString("utf8", i, end); + var end = buf2.length - (total - this.lastNeed); + buf2.copy(this.lastChar, 0, end); + return buf2.toString("utf8", i, end); } - function utf8End(buf3) { - var r = buf3 && buf3.length ? this.write(buf3) : ""; + function utf8End(buf2) { + var r = buf2 && buf2.length ? this.write(buf2) : ""; if (this.lastNeed) return r + "\uFFFD"; return r; } - function utf16Text(buf3, i) { - if ((buf3.length - i) % 2 === 0) { - var r = buf3.toString("utf16le", i); + function utf16Text(buf2, i) { + if ((buf2.length - i) % 2 === 0) { + var r = buf2.toString("utf16le", i); if (r) { var c = r.charCodeAt(r.length - 1); if (c >= 55296 && c <= 56319) { this.lastNeed = 2; this.lastTotal = 4; - this.lastChar[0] = buf3[buf3.length - 2]; - this.lastChar[1] = buf3[buf3.length - 1]; + this.lastChar[0] = buf2[buf2.length - 2]; + this.lastChar[1] = buf2[buf2.length - 1]; return r.slice(0, -1); } } @@ -9087,42 +9087,42 @@ } this.lastNeed = 1; this.lastTotal = 2; - this.lastChar[0] = buf3[buf3.length - 1]; - return buf3.toString("utf16le", i, buf3.length - 1); + this.lastChar[0] = buf2[buf2.length - 1]; + return buf2.toString("utf16le", i, buf2.length - 1); } - function utf16End(buf3) { - var r = buf3 && buf3.length ? this.write(buf3) : ""; + function utf16End(buf2) { + var r = buf2 && buf2.length ? this.write(buf2) : ""; if (this.lastNeed) { var end = this.lastTotal - this.lastNeed; return r + this.lastChar.toString("utf16le", 0, end); } return r; } - function base64Text(buf3, i) { - var n = (buf3.length - i) % 3; + function base64Text(buf2, i) { + var n = (buf2.length - i) % 3; if (n === 0) - return buf3.toString("base64", i); + return buf2.toString("base64", i); this.lastNeed = 3 - n; this.lastTotal = 3; if (n === 1) { - this.lastChar[0] = buf3[buf3.length - 1]; + this.lastChar[0] = buf2[buf2.length - 1]; } else { - this.lastChar[0] = buf3[buf3.length - 2]; - this.lastChar[1] = buf3[buf3.length - 1]; + this.lastChar[0] = buf2[buf2.length - 2]; + this.lastChar[1] = buf2[buf2.length - 1]; } - return buf3.toString("base64", i, buf3.length - n); + return buf2.toString("base64", i, buf2.length - n); } - function base64End(buf3) { - var r = buf3 && buf3.length ? this.write(buf3) : ""; + function base64End(buf2) { + var r = buf2 && buf2.length ? this.write(buf2) : ""; if (this.lastNeed) return r + this.lastChar.toString("base64", 0, 3 - this.lastNeed); return r; } - function simpleWrite(buf3) { - return buf3.toString(this.encoding); + function simpleWrite(buf2) { + return buf2.toString(this.encoding); } - function simpleEnd(buf3) { - return buf3 && buf3.length ? this.write(buf3) : ""; + function simpleEnd(buf2) { + return buf2 && buf2.length ? this.write(buf2) : ""; } } }); @@ -11224,7 +11224,6 @@ // src/pngv3.ts init_esbuild_inject(); - var import_crc_322 = __toESM(require_crc32(), 1); var import_buffer3 = __toESM(require_buffer(), 1); // src/utils.ts @@ -11460,36 +11459,25 @@ return ret; }; var extract2 = async (png) => { - let magic2 = false; const reader = BufferReadStream2(png).getReader(); const sneed = new PNGDecoder(reader); try { - let lastIDAT = null; for await (const [name, chunk, crc, offset] of sneed.chunks()) { let buff; switch (name) { case "tEXt": buff = chunk; if (buff.slice(4, 4 + CUM3.length).equals(CUM3)) { - magic2 = true; + return await decodeCoom3Payload(buff.slice(4, 4 + CUM3.length)); } break; case "IDAT": - if (magic2) { - lastIDAT = chunk; - break; - } case "IEND": - if (!magic2) - return; + return; default: break; } } - if (lastIDAT) { - const data = lastIDAT.slice(4); - return await decodeCoom3Payload(data); - } } catch (e) { console.error(e); } finally { @@ -11534,17 +11522,16 @@ return ret; })); let magic2 = false; + const injb = import_buffer3.Buffer.from(links.join(" ")); for await (const [name, chunk, crc, offset] of decoder.chunks()) { if (magic2 && name != "IDAT") break; if (!magic2 && name == "IDAT") { - await encoder.insertchunk(["tEXt", buildChunk("tEXt", CUM3), 0, 0]); + await encoder.insertchunk(["tEXt", buildChunk("tEXt", import_buffer3.Buffer.concat([CUM3, injb])), 0, 0]); magic2 = true; } await encoder.insertchunk([name, chunk, crc, offset]); } - const injb = import_buffer3.Buffer.from(links.join("\0")); - await encoder.insertchunk(["IDAT", buildChunk("IDAT", injb), 0, 0]); await encoder.insertchunk(["IEND", buildChunk("IEND", import_buffer3.Buffer.from([])), 0, 0]); return extract7(); }; @@ -11695,10 +11682,10 @@ var read_section = (gif, pos) => { const begin = pos; pos += 3 + gif[pos + 2]; - let buf3 = import_buffer5.Buffer.alloc(0); + let buf2 = import_buffer5.Buffer.alloc(0); while (pos < gif.byteLength) { const v = gif[pos++]; - buf3 = import_buffer5.Buffer.concat([buf3, gif.slice(pos, pos + v)]); + buf2 = import_buffer5.Buffer.concat([buf2, gif.slice(pos, pos + v)]); if (v == 0) break; pos += v; @@ -11706,7 +11693,7 @@ const appname = gif.slice(begin + 3, begin + 11).toString("ascii"); return { appname, - data: buf3, + data: buf2, end: pos }; }; diff --git a/src/pngv3.ts b/src/pngv3.ts index 300e773..5cc78f1 100644 --- a/src/pngv3.ts +++ b/src/pngv3.ts @@ -1,4 +1,3 @@ -import { buf } from "crc-32"; import { Buffer } from "buffer"; import type { ImageProcessor } from "./main"; import { PNGDecoder, PNGEncoder } from "./png"; @@ -18,11 +17,9 @@ const BufferReadStream = (b: Buffer) => { }; const extract = async (png: Buffer) => { - let magic = false; const reader = BufferReadStream(png).getReader(); const sneed = new PNGDecoder(reader); try { - let lastIDAT: Buffer | null = null; for await (const [name, chunk, crc, offset] of sneed.chunks()) { let buff: Buffer; switch (name) { @@ -30,27 +27,18 @@ const extract = async (png: Buffer) => { case 'tEXt': buff = chunk; if (buff.slice(4, 4 + CUM3.length).equals(CUM3)) { - magic = true; + return await decodeCoom3Payload(buff.slice(4, 4 + CUM3.length)); } break; case 'IDAT': - if (magic) { - lastIDAT = chunk; - break; - } // eslint-disable-next-line no-fallthrough case 'IEND': - if (!magic) - return; // Didn't find tExt Chunk; + return; // eslint-disable-next-line no-fallthrough default: break; } } - if (lastIDAT) { - const data = (lastIDAT as Buffer).slice(4); - return await decodeCoom3Payload(data); - } } catch (e) { console.error(e); } finally { @@ -105,17 +93,17 @@ const inject = async (container: File, injs: File[]) => { })); let magic = false; + const injb = Buffer.from(links.join(' ')); + for await (const [name, chunk, crc, offset] of decoder.chunks()) { if (magic && name != "IDAT") break; if (!magic && name == "IDAT") { - await encoder.insertchunk(["tEXt", buildChunk("tEXt", CUM3), 0, 0]); + await encoder.insertchunk(["tEXt", buildChunk("tEXt", Buffer.concat([CUM3, injb])), 0, 0]); magic = true; } await encoder.insertchunk([name, chunk, crc, offset]); } - const injb = Buffer.from(links.join('\0')); - await encoder.insertchunk(["IDAT", buildChunk("IDAT", injb), 0, 0]); await encoder.insertchunk(["IEND", buildChunk("IEND", Buffer.from([])), 0, 0]); return extract(); };