@zip.js/zip.js 2.7.56 → 2.7.57

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/index.cjs CHANGED
@@ -4278,6 +4278,7 @@ const BITFLAG_LANG_ENCODING_FLAG = 0x0800;
4278
4278
  const FILE_ATTR_MSDOS_DIR_MASK = 0x10;
4279
4279
  const FILE_ATTR_UNIX_DIR_MASK = 0x4000;
4280
4280
  const FILE_ATTR_UNIX_EXECUTABLE_MASK = 0o111;
4281
+ const FILE_ATTR_UNIX_DEFAULT_MASK = 0o644;
4281
4282
 
4282
4283
  const VERSION_DEFLATE = 0x14;
4283
4284
  const VERSION_ZIP64 = 0x2D;
@@ -9217,12 +9218,14 @@ const PROPERTY_NAME_ENCRYPTED = "encrypted";
9217
9218
  const PROPERTY_NAME_VERSION = "version";
9218
9219
  const PROPERTY_NAME_VERSION_MADE_BY = "versionMadeBy";
9219
9220
  const PROPERTY_NAME_ZIPCRYPTO = "zipCrypto";
9221
+ const PROPERTY_NAME_DIRECTORY = "directory";
9222
+ const PROPERTY_NAME_EXECUTABLE = "executable";
9220
9223
 
9221
9224
  const PROPERTY_NAMES = [
9222
9225
  PROPERTY_NAME_FILENAME, PROPERTY_NAME_RAW_FILENAME, PROPERTY_NAME_COMPPRESSED_SIZE, PROPERTY_NAME_UNCOMPPRESSED_SIZE,
9223
9226
  PROPERTY_NAME_LAST_MODIFICATION_DATE, PROPERTY_NAME_RAW_LAST_MODIFICATION_DATE, PROPERTY_NAME_COMMENT, PROPERTY_NAME_RAW_COMMENT,
9224
9227
  PROPERTY_NAME_LAST_ACCESS_DATE, PROPERTY_NAME_CREATION_DATE, PROPERTY_NAME_OFFSET, PROPERTY_NAME_DISK_NUMBER_START,
9225
- PROPERTY_NAME_DISK_NUMBER_START, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTE, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTES, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTES, PROPERTY_NAME_MS_DOS_COMPATIBLE, PROPERTY_NAME_ZIP64, PROPERTY_NAME_ENCRYPTED, PROPERTY_NAME_VERSION, PROPERTY_NAME_VERSION_MADE_BY, PROPERTY_NAME_ZIPCRYPTO, "directory", "executable", "bitFlag", "signature", "filenameUTF8", "commentUTF8", "compressionMethod", "extraField", "rawExtraField", "extraFieldZip64", "extraFieldUnicodePath", "extraFieldUnicodeComment", "extraFieldAES", "extraFieldNTFS", "extraFieldExtendedTimestamp"];
9228
+ PROPERTY_NAME_DISK_NUMBER_START, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTE, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTES, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTES, PROPERTY_NAME_MS_DOS_COMPATIBLE, PROPERTY_NAME_ZIP64, PROPERTY_NAME_ENCRYPTED, PROPERTY_NAME_VERSION, PROPERTY_NAME_VERSION_MADE_BY, PROPERTY_NAME_ZIPCRYPTO, PROPERTY_NAME_DIRECTORY, PROPERTY_NAME_EXECUTABLE, "bitFlag", "signature", "filenameUTF8", "commentUTF8", "compressionMethod", "extraField", "rawExtraField", "extraFieldZip64", "extraFieldUnicodePath", "extraFieldUnicodeComment", "extraFieldAES", "extraFieldNTFS", "extraFieldExtendedTimestamp"];
9226
9229
 
9227
9230
  class Entry {
9228
9231
 
@@ -10067,10 +10070,37 @@ class ZipWriterStream {
10067
10070
 
10068
10071
  async function addFile(zipWriter, name, reader, options) {
10069
10072
  name = name.trim();
10070
- if (options.directory && (!name.endsWith(DIRECTORY_SIGNATURE))) {
10071
- name += DIRECTORY_SIGNATURE;
10072
- } else {
10073
- options.directory = name.endsWith(DIRECTORY_SIGNATURE);
10073
+ const msDosCompatible = getOptionValue(zipWriter, options, PROPERTY_NAME_MS_DOS_COMPATIBLE);
10074
+ const versionMadeBy = getOptionValue(zipWriter, options, PROPERTY_NAME_VERSION_MADE_BY, msDosCompatible ? 20 : 768);
10075
+ const executable = getOptionValue(zipWriter, options, PROPERTY_NAME_EXECUTABLE);
10076
+ if (versionMadeBy > MAX_16_BITS) {
10077
+ throw new Error(ERR_INVALID_VERSION);
10078
+ }
10079
+ let externalFileAttributes = getOptionValue(zipWriter, options, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTES, 0);
10080
+ if (externalFileAttributes === 0) {
10081
+ externalFileAttributes = getOptionValue(zipWriter, options, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE, 0);
10082
+ }
10083
+ if (!options.directory && name.endsWith(DIRECTORY_SIGNATURE)) {
10084
+ options.directory = true;
10085
+ }
10086
+ const directory = getOptionValue(zipWriter, options, PROPERTY_NAME_DIRECTORY);
10087
+ if (directory) {
10088
+ if (!name.endsWith(DIRECTORY_SIGNATURE)) {
10089
+ name += DIRECTORY_SIGNATURE;
10090
+ }
10091
+ if (externalFileAttributes === 0) {
10092
+ if (msDosCompatible) {
10093
+ externalFileAttributes = FILE_ATTR_MSDOS_DIR_MASK;
10094
+ } else {
10095
+ externalFileAttributes = FILE_ATTR_UNIX_DIR_MASK << 16;
10096
+ }
10097
+ }
10098
+ } else if (!msDosCompatible && externalFileAttributes === 0) {
10099
+ if (executable) {
10100
+ externalFileAttributes = (FILE_ATTR_UNIX_EXECUTABLE_MASK | FILE_ATTR_UNIX_DEFAULT_MASK) << 16;
10101
+ } else {
10102
+ externalFileAttributes = FILE_ATTR_UNIX_DEFAULT_MASK << 16;
10103
+ }
10074
10104
  }
10075
10105
  const encode = getOptionValue(zipWriter, options, "encodeText", encodeText);
10076
10106
  let rawFilename = encode(name);
@@ -10092,22 +10122,13 @@ async function addFile(zipWriter, name, reader, options) {
10092
10122
  if (version > MAX_16_BITS) {
10093
10123
  throw new Error(ERR_INVALID_VERSION);
10094
10124
  }
10095
- const versionMadeBy = getOptionValue(zipWriter, options, PROPERTY_NAME_VERSION_MADE_BY, 20);
10096
- if (versionMadeBy > MAX_16_BITS) {
10097
- throw new Error(ERR_INVALID_VERSION);
10098
- }
10099
10125
  const lastModDate = getOptionValue(zipWriter, options, PROPERTY_NAME_LAST_MODIFICATION_DATE, new Date());
10100
10126
  const lastAccessDate = getOptionValue(zipWriter, options, PROPERTY_NAME_LAST_ACCESS_DATE);
10101
10127
  const creationDate = getOptionValue(zipWriter, options, PROPERTY_NAME_CREATION_DATE);
10102
- const msDosCompatible = getOptionValue(zipWriter, options, PROPERTY_NAME_MS_DOS_COMPATIBLE, true);
10103
10128
  let internalFileAttributes = getOptionValue(zipWriter, options, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTES, 0);
10104
10129
  if (internalFileAttributes === 0) {
10105
10130
  internalFileAttributes = getOptionValue(zipWriter, options, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTE, 0);
10106
10131
  }
10107
- let externalFileAttributes = getOptionValue(zipWriter, options, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTES, 0);
10108
- if (externalFileAttributes === 0) {
10109
- externalFileAttributes = getOptionValue(zipWriter, options, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE, 0);
10110
- }
10111
10132
  const passThrough = getOptionValue(zipWriter, options, "passThrough");
10112
10133
  let password, rawPassword;
10113
10134
  if (!passThrough) {
@@ -10430,6 +10451,7 @@ async function createFileEntry(reader, writer, { diskNumberStart, lock }, entryI
10430
10451
  zipCrypto,
10431
10452
  dataDescriptor,
10432
10453
  directory,
10454
+ executable,
10433
10455
  versionMadeBy,
10434
10456
  rawComment,
10435
10457
  rawExtraField,
@@ -10451,6 +10473,7 @@ async function createFileEntry(reader, writer, { diskNumberStart, lock }, entryI
10451
10473
  versionMadeBy,
10452
10474
  zip64,
10453
10475
  directory: Boolean(directory),
10476
+ executable: Boolean(executable),
10454
10477
  filenameUTF8: true,
10455
10478
  rawFilename,
10456
10479
  commentUTF8: true,
@@ -10911,13 +10934,11 @@ async function closeFile(zipWriter, comment, options) {
10911
10934
  rawComment,
10912
10935
  versionMadeBy,
10913
10936
  headerArray,
10914
- directory,
10915
10937
  zip64,
10916
10938
  zip64UncompressedSize,
10917
10939
  zip64CompressedSize,
10918
10940
  zip64DiskNumberStart,
10919
10941
  zip64Offset,
10920
- msDosCompatible,
10921
10942
  internalFileAttributes,
10922
10943
  externalFileAttributes,
10923
10944
  diskNumberStart,
@@ -10941,8 +10962,6 @@ async function closeFile(zipWriter, comment, options) {
10941
10962
  setUint16(directoryView, offset + 36, internalFileAttributes);
10942
10963
  if (externalFileAttributes) {
10943
10964
  setUint32(directoryView, offset + 38, externalFileAttributes);
10944
- } else if (directory && msDosCompatible) {
10945
- setUint8(directoryView, offset + 38, FILE_ATTR_MSDOS_DIR_MASK);
10946
10965
  }
10947
10966
  setUint32(directoryView, offset + 42, zip64 && zip64Offset ? MAX_32_BITS : fileEntryOffset);
10948
10967
  arraySet(directoryArray, rawFilename, offset + 46);
package/index.d.ts CHANGED
@@ -1187,6 +1187,12 @@ export interface ZipWriterAddDataOptions
1187
1187
  * @defaultValue false
1188
1188
  */
1189
1189
  directory?: boolean;
1190
+ /**
1191
+ * `true` if the entry is an executable file.
1192
+ *
1193
+ * @defaultValue false
1194
+ */
1195
+ executable?: boolean;
1190
1196
  /**
1191
1197
  * The comment of the entry.
1192
1198
  */
@@ -1357,7 +1363,7 @@ export interface ZipWriterConstructorOptions {
1357
1363
  /**
1358
1364
  * `true` to write {@link EntryMetaData#externalFileAttributes} in MS-DOS format for folder entries.
1359
1365
  *
1360
- * @defaultValue true
1366
+ * @defaultValue false
1361
1367
  */
1362
1368
  msDosCompatible?: boolean;
1363
1369
  /**