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

Function addFile

index.cjs:4587–4869  ·  view source on GitHub ↗
(zipWriter, name, reader, options)

Source from the content-addressed store, hash-verified

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

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…