Skip to content

Commit

Permalink
add constants
Browse files Browse the repository at this point in the history
  • Loading branch information
gildas-lormeau committed Aug 21, 2024
1 parent 1c59627 commit d4db031
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
11 changes: 7 additions & 4 deletions lib/core/zip-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,19 @@ const PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTE = "internalFileAttribute";
const PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE = "externalFileAttribute";
const PROPERTY_NAME_MS_DOS_COMPATIBLE = "msDosCompatible";
const PROPERTY_NAME_ZIP64 = "zip64";
const PROPERTY_NAME_ENCRYPTED = "encrypted";
const PROPERTY_NAME_VERSION = "version";
const PROPERTY_NAME_VERSION_MADE_BY = "versionMadeBy";
const PROPERTY_NAME_ZIPCRYPTO = "zipCrypto";

const PROPERTY_NAMES = [
PROPERTY_NAME_FILENAME, PROPERTY_NAME_RAW_FILENAME, PROPERTY_NAME_COMPPRESSED_SIZE, PROPERTY_NAME_UNCOMPPRESSED_SIZE,
PROPERTY_NAME_LAST_MODIFICATION_DATE, PROPERTY_NAME_RAW_LAST_MODIFICATION_DATE, PROPERTY_NAME_COMMENT, PROPERTY_NAME_RAW_COMMENT,
PROPERTY_NAME_LAST_ACCESS_DATE, PROPERTY_NAME_CREATION_DATE, PROPERTY_NAME_OFFSET, PROPERTY_NAME_DISK_NUMBER_START,
PROPERTY_NAME_DISK_NUMBER_START, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTE, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE,
PROPERTY_NAME_MS_DOS_COMPATIBLE, PROPERTY_NAME_ZIP64,
"directory", "bitFlag", "encrypted", "signature", "filenameUTF8", "commentUTF8", "compressionMethod", "version", "versionMadeBy",
"extraField", "rawExtraField", "extraFieldZip64", "extraFieldUnicodePath", "extraFieldUnicodeComment", "extraFieldAES", "extraFieldNTFS",
"extraFieldExtendedTimestamp", "zipCrypto"];
PROPERTY_NAME_MS_DOS_COMPATIBLE, PROPERTY_NAME_ZIP64, PROPERTY_NAME_ENCRYPTED, PROPERTY_NAME_VERSION, PROPERTY_NAME_VERSION_MADE_BY,
PROPERTY_NAME_ZIPCRYPTO, "directory", "bitFlag", "signature", "filenameUTF8", "commentUTF8", "compressionMethod", "extraField", "rawExtraField",
"extraFieldZip64", "extraFieldUnicodePath", "extraFieldUnicodeComment", "extraFieldAES", "extraFieldNTFS", "extraFieldExtendedTimestamp"];

class Entry {

Expand Down
14 changes: 9 additions & 5 deletions lib/core/zip-writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ import {
PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE,
PROPERTY_NAME_MS_DOS_COMPATIBLE,
PROPERTY_NAME_ZIP64,
PROPERTY_NAME_ENCRYPTED,
PROPERTY_NAME_VERSION,
PROPERTY_NAME_VERSION_MADE_BY,
PROPERTY_NAME_ZIPCRYPTO,
Entry
} from "./zip-entry.js";

Expand Down Expand Up @@ -242,11 +246,11 @@ async function addFile(zipWriter, name, reader, options) {
if (getLength(rawComment) > MAX_16_BITS) {
throw new Error(ERR_INVALID_ENTRY_COMMENT);
}
const version = getOptionValue(zipWriter, options, "version", VERSION_DEFLATE);
const version = getOptionValue(zipWriter, options, PROPERTY_NAME_VERSION, VERSION_DEFLATE);
if (version > MAX_16_BITS) {
throw new Error(ERR_INVALID_VERSION);
}
const versionMadeBy = getOptionValue(zipWriter, options, "versionMadeBy", 20);
const versionMadeBy = getOptionValue(zipWriter, options, PROPERTY_NAME_VERSION_MADE_BY, 20);
if (versionMadeBy > MAX_16_BITS) {
throw new Error(ERR_INVALID_VERSION);
}
Expand All @@ -263,7 +267,7 @@ async function addFile(zipWriter, name, reader, options) {
rawPassword = getOptionValue(zipWriter, options, "rawPassword");
}
const encryptionStrength = getOptionValue(zipWriter, options, "encryptionStrength", 3);
const zipCrypto = getOptionValue(zipWriter, options, "zipCrypto");
const zipCrypto = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIPCRYPTO);
const extendedTimestamp = getOptionValue(zipWriter, options, "extendedTimestamp", true);
const keepOrder = getOptionValue(zipWriter, options, "keepOrder", true);
const level = getOptionValue(zipWriter, options, "level");
Expand Down Expand Up @@ -340,7 +344,7 @@ async function addFile(zipWriter, name, reader, options) {
}
}
zip64 = zip64 || false;
const encrypted = getOptionValue(zipWriter, options, "encrypted");
const encrypted = getOptionValue(zipWriter, options, PROPERTY_NAME_ENCRYPTED);
const { signature } = options;
options = Object.assign({}, options, {
rawFilename,
Expand Down Expand Up @@ -1116,7 +1120,7 @@ async function closeFile(zipWriter, comment, options) {
if (availableSize < END_OF_CENTRAL_DIR_LENGTH) {
lastDiskNumber++;
}
let zip64 = getOptionValue(zipWriter, options, "zip64");
let zip64 = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIP64);
if (directoryOffset > MAX_32_BITS || directoryDataLength > MAX_32_BITS || filesLength > MAX_16_BITS || lastDiskNumber > MAX_16_BITS) {
if (zip64 === false) {
throw new Error(ERR_UNSUPPORTED_FORMAT);
Expand Down

0 comments on commit d4db031

Please sign in to comment.