Skip to content

Commit 054cd74

Browse files
add constants
1 parent 30476a3 commit 054cd74

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

lib/core/constants.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
const MAX_32_BITS = 0xffffffff;
3030
const MAX_16_BITS = 0xffff;
31+
const MAX_8_BITS = 0xff;
3132
const COMPRESSION_METHOD_DEFLATE = 0x08;
3233
const COMPRESSION_METHOD_DEFLATE_64 = 0x09;
3334
const COMPRESSION_METHOD_STORE = 0x00;
@@ -88,10 +89,12 @@ const MIN_DATE = new Date(1980, 0, 1);
8889
const UNDEFINED_VALUE = undefined;
8990
const UNDEFINED_TYPE = "undefined";
9091
const FUNCTION_TYPE = "function";
92+
const OBJECT_TYPE = "object";
9193

9294
export {
9395
MAX_32_BITS,
9496
MAX_16_BITS,
97+
MAX_8_BITS,
9598
COMPRESSION_METHOD_DEFLATE,
9699
COMPRESSION_METHOD_DEFLATE_64,
97100
COMPRESSION_METHOD_STORE,
@@ -142,5 +145,6 @@ export {
142145
MAX_DATE,
143146
UNDEFINED_VALUE,
144147
UNDEFINED_TYPE,
145-
FUNCTION_TYPE
148+
FUNCTION_TYPE,
149+
OBJECT_TYPE
146150
};

lib/core/zip-reader.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import {
3333
MAX_32_BITS,
3434
MAX_16_BITS,
35+
MAX_8_BITS,
3536
COMPRESSION_METHOD_DEFLATE,
3637
COMPRESSION_METHOD_STORE,
3738
COMPRESSION_METHOD_AES,
@@ -142,6 +143,7 @@ const ERR_UNSUPPORTED_COMPRESSION = "Compression method not supported";
142143
const ERR_SPLIT_ZIP_FILE = "Split zip file";
143144
const ERR_OVERLAPPING_ENTRY = "Overlapping entry found";
144145
const CHARSET_UTF8 = "utf-8";
146+
const PROPERTY_NAME_UTF8_SUFFIX = "UTF8";
145147
const CHARSET_CP437 = "cp437";
146148
const ZIP64_PROPERTIES = [
147149
[PROPERTY_NAME_UNCOMPRESSED_SIZE, MAX_32_BITS],
@@ -534,7 +536,7 @@ class ZipEntry {
534536
zipCrypto,
535537
encryptionStrength: extraFieldAES && extraFieldAES.strength,
536538
signed: getOptionValue(zipEntry, options, OPTION_CHECK_SIGNATURE) && !passThrough,
537-
passwordVerification: zipCrypto && (dataDescriptor ? ((rawLastModDate >>> 8) & 0xFF) : ((signature >>> 24) & 0xFF)),
539+
passwordVerification: zipCrypto && (dataDescriptor ? ((rawLastModDate >>> 8) & MAX_8_BITS) : ((signature >>> 24) & MAX_8_BITS)),
538540
outputSize: passThrough ? compressedSize : uncompressedSize,
539541
signature,
540542
compressed: compressionMethod != 0 && !passThrough,
@@ -706,7 +708,7 @@ function readExtraFieldUnicode(extraFieldUnicode, propertyName, rawPropertyName,
706708
});
707709
if (extraFieldUnicode.valid) {
708710
directory[propertyName] = extraFieldUnicode[propertyName];
709-
directory[propertyName + "UTF8"] = true;
711+
directory[propertyName + PROPERTY_NAME_UTF8_SUFFIX] = true;
710712
}
711713
}
712714

@@ -888,7 +890,7 @@ function getOptionValue(zipReader, options, name) {
888890
}
889891

890892
function getDate(timeRaw) {
891-
const date = (timeRaw & 0xffff0000) >> 16, time = timeRaw & 0x0000ffff;
893+
const date = (timeRaw & 0xffff0000) >> 16, time = timeRaw & MAX_16_BITS;
892894
try {
893895
return new Date(1980 + ((date & 0xFE00) >> 9), ((date & 0x01E0) >> 5) - 1, date & 0x001F, (time & 0xF800) >> 11, (time & 0x07E0) >> 5, (time & 0x001F) * 2, 0);
894896
} catch {

lib/core/zip-writer.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import {
3333
MAX_32_BITS,
3434
MAX_16_BITS,
35+
MAX_8_BITS,
3536
COMPRESSION_METHOD_DEFLATE,
3637
COMPRESSION_METHOD_DEFLATE_64,
3738
COMPRESSION_METHOD_STORE,
@@ -76,7 +77,8 @@ import {
7677
HEADER_OFFSET_UNCOMPRESSED_SIZE,
7778
MIN_DATE,
7879
MAX_DATE,
79-
UNDEFINED_VALUE
80+
UNDEFINED_VALUE,
81+
OBJECT_TYPE
8082
} from "./constants.js";
8183
import {
8284
getConfiguration,
@@ -342,7 +344,7 @@ class ZipWriterStream {
342344
return writable;
343345
}
344346

345-
close(comment = undefined, options = {}) {
347+
close(comment = UNDEFINED_VALUE, options = {}) {
346348
return this.zipWriter.close(comment, options);
347349
}
348350
}
@@ -825,7 +827,7 @@ async function createFileEntry(reader, writer, { diskNumberStart, lock }, entryI
825827
password,
826828
encryptionStrength,
827829
zipCrypto: encrypted && zipCrypto,
828-
passwordVerification: encrypted && zipCrypto && (rawLastModDate >> 8) & 0xFF,
830+
passwordVerification: encrypted && zipCrypto && (rawLastModDate >> 8) & MAX_8_BITS,
829831
signed: !passThrough,
830832
compressed: compressed && !passThrough,
831833
encrypted: encrypted && !passThrough,

0 commit comments

Comments
 (0)