mirror of
https://github.com/jakejarvis/careful-downloader.git
synced 2025-04-28 02:20:28 -04:00
fs.exists()
(deprecated) -> fs.access()
This commit is contained in:
parent
efbca27fd0
commit
9454810eab
6
index.js
6
index.js
@ -93,14 +93,14 @@ export default async (downloadUrl, options) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// optionally clear the target directory of existing files
|
// 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}'`);
|
debug(`Deleting contents of '${options.destDir}'`);
|
||||||
await fs.remove(options.destDir);
|
await fs.emptyDir(options.destDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ensure the target directory exists
|
// ensure the target directory exists
|
||||||
debug(`Ensuring target '${options.destDir}' exists`);
|
debug(`Ensuring target '${options.destDir}' exists`);
|
||||||
await fs.mkdirp(options.destDir);
|
await fs.ensureDir(options.destDir);
|
||||||
|
|
||||||
if (options.extract) {
|
if (options.extract) {
|
||||||
// decompress download and move resulting files to final destination
|
// decompress download and move resulting files to final destination
|
||||||
|
@ -50,7 +50,7 @@ export const checksumViaString = async (desiredFile, correctHash, algorithm, enc
|
|||||||
|
|
||||||
// Takes a path to a file and returns its hash.
|
// Takes a path to a file and returns its hash.
|
||||||
const generateHashFromFile = async (file, algorithm, encoding) => {
|
const generateHashFromFile = async (file, algorithm, encoding) => {
|
||||||
const fileBuffer = fs.readFileSync(file);
|
const fileBuffer = await fs.readFile(file);
|
||||||
const hashSum = crypto.createHash(algorithm);
|
const hashSum = crypto.createHash(algorithm);
|
||||||
hashSum.update(fileBuffer);
|
hashSum.update(fileBuffer);
|
||||||
|
|
||||||
@ -61,7 +61,7 @@ const generateHashFromFile = async (file, algorithm, encoding) => {
|
|||||||
// https://github.com/malept/sumchecker/blob/28aed640a02787490d033fda56eaee30e24e5a71/src/index.ts#L97
|
// https://github.com/malept/sumchecker/blob/28aed640a02787490d033fda56eaee30e24e5a71/src/index.ts#L97
|
||||||
const parseChecksumFile = async (checksumFile) => {
|
const parseChecksumFile = async (checksumFile) => {
|
||||||
// read the text file holding one or more checksums
|
// 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
|
// https://regexr.com/67k7i
|
||||||
const lineRegex = /^([\da-fA-F]+)[ \t]+[*]?(.+)$/;
|
const lineRegex = /^([\da-fA-F]+)[ \t]+[*]?(.+)$/;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user