MCPcopy
hub / github.com/gildas-lormeau/zip.js / addFile

Function addFile

index-native.cjs:4583–4865  ·  view source on GitHub ↗
(zipWriter, name, reader, options)

Source from the content-addressed store, hash-verified

4581}
4582
4583async function addFile(zipWriter, name, reader, options) {
4584 name = name.trim();
4585 let msDosCompatible = getOptionValue(zipWriter, options, PROPERTY_NAME_MS_DOS_COMPATIBLE);
4586 let versionMadeBy = getOptionValue(zipWriter, options, PROPERTY_NAME_VERSION_MADE_BY, msDosCompatible ? 20 : 768);
4587 const executable = getOptionValue(zipWriter, options, PROPERTY_NAME_EXECUTABLE);
4588 const uid = getOptionValue(zipWriter, options, PROPERTY_NAME_UID);
4589 const gid = getOptionValue(zipWriter, options, PROPERTY_NAME_GID);
4590 let unixMode = getOptionValue(zipWriter, options, PROPERTY_NAME_UNIX_MODE);
4591 const unixExtraFieldType = getOptionValue(zipWriter, options, OPTION_UNIX_EXTRA_FIELD_TYPE);
4592 let setuid = getOptionValue(zipWriter, options, PROPERTY_NAME_SETUID);
4593 let setgid = getOptionValue(zipWriter, options, PROPERTY_NAME_SETGID);
4594 let sticky = getOptionValue(zipWriter, options, PROPERTY_NAME_STICKY);
4595 if (uid !== UNDEFINED_VALUE && (uid < 0 || uid > MAX_32_BITS)) {
4596 throw new Error(ERR_INVALID_UID);
4597 }
4598 if (gid !== UNDEFINED_VALUE && (gid < 0 || gid > MAX_32_BITS)) {
4599 throw new Error(ERR_INVALID_GID);
4600 }
4601 if (unixMode !== UNDEFINED_VALUE && (unixMode < 0 || unixMode > MAX_16_BITS)) {
4602 throw new Error(ERR_INVALID_UNIX_MODE);
4603 }
4604 if (unixExtraFieldType !== UNDEFINED_VALUE && unixExtraFieldType !== INFOZIP_EXTRA_FIELD_TYPE && unixExtraFieldType !== UNIX_EXTRA_FIELD_TYPE) {
4605 throw new Error(ERR_INVALID_UNIX_EXTRA_FIELD_TYPE);
4606 }
4607 let msdosAttributesRaw = getOptionValue(zipWriter, options, PROPERTY_NAME_MSDOS_ATTRIBUTES_RAW);
4608 let msdosAttributes = getOptionValue(zipWriter, options, PROPERTY_NAME_MSDOS_ATTRIBUTES);
4609 const hasUnixMetadata = uid !== UNDEFINED_VALUE || gid !== UNDEFINED_VALUE || unixMode !== UNDEFINED_VALUE || unixExtraFieldType;
4610 const hasMsDosProvided = msdosAttributesRaw !== UNDEFINED_VALUE || msdosAttributes !== UNDEFINED_VALUE;
4611 if (hasUnixMetadata) {
4612 msDosCompatible = false;
4613 versionMadeBy = (versionMadeBy & MAX_16_BITS) | (3 << 8);
4614 } else if (hasMsDosProvided) {
4615 msDosCompatible = true;
4616 versionMadeBy = (versionMadeBy & MAX_8_BITS);
4617 }
4618 if (msdosAttributesRaw !== UNDEFINED_VALUE && (msdosAttributesRaw < 0 || msdosAttributesRaw > MAX_8_BITS)) {
4619 throw new Error(ERR_INVALID_MSDOS_ATTRIBUTES);
4620 }
4621 if (msdosAttributes && typeof msdosAttributes !== OBJECT_TYPE) {
4622 throw new Error(ERR_INVALID_MSDOS_DATA);
4623 }
4624 if (versionMadeBy > MAX_16_BITS) {
4625 throw new Error(ERR_INVALID_VERSION);
4626 }
4627 let externalFileAttributes = getOptionValue(zipWriter, options, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTES, 0);
4628 if (!options[PROPERTY_NAME_DIRECTORY] && name.endsWith(DIRECTORY_SIGNATURE)) {
4629 options[PROPERTY_NAME_DIRECTORY] = true;
4630 }
4631 const directory = getOptionValue(zipWriter, options, PROPERTY_NAME_DIRECTORY);
4632 if (directory) {
4633 if (!name.endsWith(DIRECTORY_SIGNATURE)) {
4634 name += DIRECTORY_SIGNATURE;
4635 }
4636 if (externalFileAttributes === 0) {
4637 externalFileAttributes = FILE_ATTR_MSDOS_DIR_MASK;
4638 if (!msDosCompatible) {
4639 externalFileAttributes |= (FILE_ATTR_UNIX_TYPE_DIR | FILE_ATTR_UNIX_EXECUTABLE_MASK | FILE_ATTR_UNIX_DEFAULT_MASK) << 16;
4640 }

Callers 2

addMethod · 0.70
addFileSystemHandleFunction · 0.70

Calls 13

getOptionValueFunction · 0.70
normalizeMsdosAttributesFunction · 0.70
encodeTextFunction · 0.70
getLengthFunction · 0.70
arraySetFunction · 0.70
initStreamFunction · 0.70
getMaximumCompressedSizeFunction · 0.70
getHeaderInfoFunction · 0.70
getDataDescriptorInfoFunction · 0.70
getFileEntryFunction · 0.70
addDataMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…