1
mirror of https://github.com/jakejarvis/careful-downloader.git synced 2025-04-25 16:35:24 -04:00

fs.exists() (deprecated) -> fs.access()

This commit is contained in:
Jake Jarvis 2021-10-16 09:53:32 -04:00
parent efbca27fd0
commit 9454810eab
Signed by: jake
GPG Key ID: 2B0C9CF251E69A39
2 changed files with 5 additions and 5 deletions

View File

@ -93,14 +93,14 @@ export default async (downloadUrl, options) => {
}
// optionally clear the target directory of existing files
if (options.cleanDestDir && fs.existsSync(options.destDir)) {
if (options.cleanDestDir && await fs.access(options.destDir)) {
debug(`Deleting contents of '${options.destDir}'`);
await fs.remove(options.destDir);
await fs.emptyDir(options.destDir);
}
// ensure the target directory exists
debug(`Ensuring target '${options.destDir}' exists`);
await fs.mkdirp(options.destDir);
await fs.ensureDir(options.destDir);
if (options.extract) {
// decompress download and move resulting files to final destination

View File

@ -50,7 +50,7 @@ export const checksumViaString = async (desiredFile, correctHash, algorithm, enc
// Takes a path to a file and returns its hash.
const generateHashFromFile = async (file, algorithm, encoding) => {
const fileBuffer = fs.readFileSync(file);
const fileBuffer = await fs.readFile(file);
const hashSum = crypto.createHash(algorithm);
hashSum.update(fileBuffer);
@ -61,7 +61,7 @@ const generateHashFromFile = async (file, algorithm, encoding) => {
// https://github.com/malept/sumchecker/blob/28aed640a02787490d033fda56eaee30e24e5a71/src/index.ts#L97
const parseChecksumFile = async (checksumFile) => {
// read the text file holding one or more checksums
const data = fs.readFileSync(checksumFile, { encoding: "utf8" });
const data = await fs.readFile(checksumFile, { encoding: "utf8" });
// https://regexr.com/67k7i
const lineRegex = /^([\da-fA-F]+)[ \t]+[*]?(.+)$/;