single-file-core 1.6.20 → 1.6.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "single-file-core",
3
- "version": "1.6.20",
3
+ "version": "1.6.22",
4
4
  "description": "SingleFile Core",
5
5
  "author": "Gildas Lormeau",
6
6
  "license": "AGPL-3.0-or-later",
@@ -970,7 +970,7 @@ async function getContent() {
970
970
  if (offset != zipDataLength || indexLFCode != lfCodesLength || crc32 != expectedCRC32) {
971
971
  throw new Error("Invalid checksum of the extracted zip data");
972
972
  }
973
- return new Blob([zipData], { type: "application/octet-stream" });
973
+ return new Blob([new Uint8Array(getPrependedDataLength(zipData)), zipData], { type: "application/octet-stream" });
974
974
 
975
975
  function writeByte(byte) {
976
976
  zipData[offset] = byte;
@@ -979,6 +979,22 @@ async function getContent() {
979
979
  }
980
980
  }
981
981
 
982
+ function getPrependedDataLength(zipData) {
983
+ const view = new DataView(zipData.buffer, zipData.byteOffset, zipData.length);
984
+ const endOfDirectoryOffset = zipData.length - 22;
985
+ const locatorOffset = endOfDirectoryOffset - 20;
986
+ if (endOfDirectoryOffset < 0 || view.getUint32(endOfDirectoryOffset, true) != 0x06054b50) {
987
+ return 0;
988
+ }
989
+ let storedDirectoryOffset = view.getUint32(endOfDirectoryOffset + 16, true);
990
+ let directoryOffset = endOfDirectoryOffset - view.getUint32(endOfDirectoryOffset + 12, true);
991
+ if (locatorOffset >= 0 && view.getUint32(locatorOffset, true) == 0x07064b50) {
992
+ storedDirectoryOffset = view.getUint32(locatorOffset + 8, true) + view.getUint32(locatorOffset + 12, true) * 0x100000000;
993
+ directoryOffset = locatorOffset - 56;
994
+ }
995
+ return Math.max(0, storedDirectoryOffset - directoryOffset);
996
+ }
997
+
982
998
  function base64Decode(b64) {
983
999
  b64 = String(b64).replace(/[^A-Za-z0-9+/=]/g, "");
984
1000
  const len = b64.length;