Skip to content

Commit

Permalink
use constants
Browse files Browse the repository at this point in the history
  • Loading branch information
gildas-lormeau committed Jan 29, 2024
1 parent 65f352b commit 6033b40
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 10 deletions.
4 changes: 1 addition & 3 deletions lib/core/streams/aes-crypto-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
/* global crypto, TransformStream */
// deno-lint-ignore-file no-this-alias

import { UNDEFINED_VALUE } from "../constants.js";
import { UNDEFINED_VALUE, UNDEFINED_TYPE, FUNCTION_TYPE } from "../constants.js";
import { encodeText } from "./../util/encode-text.js";
import {
cipher,
Expand All @@ -56,8 +56,6 @@ const SALT_LENGTH = [8, 12, 16];
const KEY_LENGTH = [16, 24, 32];
const SIGNATURE_LENGTH = 10;
const COUNTER_DEFAULT_VALUE = [0, 0, 0, 0];
const UNDEFINED_TYPE = "undefined";
const FUNCTION_TYPE = "function";
// deno-lint-ignore valid-typeof
const CRYPTO_API_SUPPORTED = typeof crypto != UNDEFINED_TYPE;
const subtle = CRYPTO_API_SUPPORTED && crypto.subtle;
Expand Down
3 changes: 2 additions & 1 deletion lib/core/streams/common-crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@

/* global crypto */

import { FUNCTION_TYPE, UNDEFINED_TYPE } from "../constants.js";
import {
random
} from "./codecs/sjcl.js";

const GET_RANDOM_VALUES_SUPPORTED = typeof crypto != "undefined" && typeof crypto.getRandomValues == "function";
const GET_RANDOM_VALUES_SUPPORTED = typeof crypto != UNDEFINED_TYPE && typeof crypto.getRandomValues == FUNCTION_TYPE;

const ERR_INVALID_PASSWORD = "Invalid password";
const ERR_INVALID_SIGNATURE = "Invalid signature";
Expand Down
6 changes: 4 additions & 2 deletions lib/core/util/stream-codec-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

// deno-lint-ignore-file no-this-alias

import { FUNCTION_TYPE, UNDEFINED_VALUE } from "../constants.js";

export {
initShimAsyncCodec
};
Expand All @@ -42,7 +44,7 @@ function initShimAsyncCodec(library, options = {}, registerDataHandler) {

function objectHasOwn(object, propertyName) {
// eslint-disable-next-line no-prototype-builtins
return typeof Object.hasOwn === "function" ? Object.hasOwn(object, propertyName) : object.hasOwnProperty(propertyName);
return typeof Object.hasOwn === FUNCTION_TYPE ? Object.hasOwn(object, propertyName) : object.hasOwnProperty(propertyName);
}

function createCodecClass(constructor, constructorOptions, registerDataHandler) {
Expand All @@ -61,7 +63,7 @@ function createCodecClass(constructor, constructorOptions, registerDataHandler)
codecAdapter.pendingData = new Uint8Array(data);
}
};
if (objectHasOwn(options, "level") && options.level === undefined) {
if (objectHasOwn(options, "level") && options.level === UNDEFINED_VALUE) {
delete options.level;
}
codecAdapter.codec = new constructor(Object.assign({}, constructorOptions, options));
Expand Down
3 changes: 2 additions & 1 deletion lib/core/zip-fs-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import {
import {
Entry
} from "./zip-entry.js";
import { UNDEFINED_VALUE } from "./constants.js";

class ZipEntry {

Expand Down Expand Up @@ -433,7 +434,7 @@ class ZipDirectoryEntry extends ZipEntry {

async exportZip(writer, options) {
const zipEntry = this;
if (options.bufferedWrite === undefined) {
if (options.bufferedWrite === UNDEFINED_VALUE) {
options.bufferedWrite = true;
}
await Promise.all([initReaders(zipEntry, options.readerOptions), initStream(writer)]);
Expand Down
2 changes: 1 addition & 1 deletion lib/core/zip-reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ class ZipEntry {
await writable.getWriter().close();
}
}
return checkPasswordOnly ? undefined : writer.getData ? writer.getData() : writable;
return checkPasswordOnly ? UNDEFINED_VALUE : writer.getData ? writer.getData() : writable;
}
}

Expand Down
3 changes: 2 additions & 1 deletion lib/z-worker-bootstrap-fflate.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@

import "./core/z-worker-core.js";
import { initShimAsyncCodec } from "./core/util/stream-codec-shim.js";
import { UNDEFINED_VALUE } from "./core/constants.js";

self.initCodec = () => {
const { Deflate, Inflate } = initShimAsyncCodec(fflate, undefined, (codec, onData) => codec.ondata = onData);
const { Deflate, Inflate } = initShimAsyncCodec(fflate, UNDEFINED_VALUE, (codec, onData) => codec.ondata = onData);
self.Deflate = Deflate;
self.Inflate = Inflate;
};
4 changes: 3 additions & 1 deletion lib/zip-fflate-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,7 @@ import {
Inflate as FflateInflate
} from "fflate";
import { initShimAsyncCodec } from "./core/util/stream-codec-shim.js";
const { Deflate, Inflate } = initShimAsyncCodec({ Deflate: FflateDeflate, Inflate: FflateInflate }, undefined, (codec, onData) => codec.ondata = onData);
import { UNDEFINED_VALUE } from "./core/constants.js";

const { Deflate, Inflate } = initShimAsyncCodec({ Deflate: FflateDeflate, Inflate: FflateInflate }, UNDEFINED_VALUE, (codec, onData) => codec.ondata = onData);
export { Deflate, Inflate };

0 comments on commit 6033b40

Please sign in to comment.