Add case insensitivity checks for Mac and Linux platforms
This commit is contained in:
@@ -4,24 +4,47 @@ import _ from "lodash";
|
||||
import deepLowerCaseKeys from "../../util/deepLowercaseKeys";
|
||||
import errorTypeCheck from "../../util/errorTypeCheck";
|
||||
import { DecodedPfh } from "./decode-pfh.interface";
|
||||
import { platform } from "os";
|
||||
import { findFileCaseInsensitive } from "./decoder-utils";
|
||||
|
||||
const DecodePfh = async (
|
||||
extensionlessFilePath: string,
|
||||
): Promise<DecodedPfh> => {
|
||||
let dbf: DBFFile | null = null;
|
||||
try {
|
||||
dbf = await DBFFile.open(`${extensionlessFilePath}.PFH`);
|
||||
} catch (error) {
|
||||
log.error("Error opening PFH File.", errorTypeCheck(error));
|
||||
dbf = await DBFFile.open(`${extensionlessFilePath}.PFH`);
|
||||
log.log("Trying to find PFH file using regular CIECA Id.");
|
||||
}
|
||||
if (platform.isWindows) {
|
||||
try {
|
||||
dbf = await DBFFile.open(`${extensionlessFilePath}.PFH`);
|
||||
} catch (error) {
|
||||
log.error("Error opening PFH File.", errorTypeCheck(error));
|
||||
dbf = await DBFFile.open(`${extensionlessFilePath}.PFH`);
|
||||
log.log("Trying to find PFH file using regular CIECA Id.");
|
||||
}
|
||||
|
||||
if (!dbf) {
|
||||
log.error(`Could not find any PFH files at ${extensionlessFilePath}`);
|
||||
throw new Error(`Could not find any PFH files at ${extensionlessFilePath}`);
|
||||
if (!dbf) {
|
||||
log.error(`Could not find any PFH files at ${extensionlessFilePath}`);
|
||||
throw new Error(
|
||||
`Could not find any PFH files at ${extensionlessFilePath}`,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
const possibleExtensions: string[] = [".pfh"];
|
||||
const filePath = await findFileCaseInsensitive(
|
||||
extensionlessFilePath,
|
||||
possibleExtensions,
|
||||
);
|
||||
try {
|
||||
if (!filePath) {
|
||||
log.error(`Could not find any PFH files at ${extensionlessFilePath}`);
|
||||
throw new Error(
|
||||
`Could not find any PFH files at ${extensionlessFilePath}`,
|
||||
);
|
||||
}
|
||||
dbf = await DBFFile.open(filePath);
|
||||
} catch (error) {
|
||||
log.error("Error opening PFH File.", errorTypeCheck(error));
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
const rawDBFRecord = await dbf.readRecords(1);
|
||||
|
||||
//AD2 will always have only 1 row.
|
||||
|
||||
Reference in New Issue
Block a user