1
mirror of https://github.com/jakejarvis/careful-downloader.git synced 2025-04-28 06:50:31 -04:00

Compare commits

...

9 Commits
v2.0.0 ... main

Author SHA1 Message Date
4e59dcbc0a
v3.0.0 2023-05-25 09:39:00 -04:00
0b51c8bbcb
bump deps and require node 14 2023-05-25 09:38:30 -04:00
dependabot[bot]
caf7571aa4 📦 npm: Bump http-cache-semantics from 4.1.0 to 4.1.1
Bumps [http-cache-semantics](https://github.com/kornelski/http-cache-semantics) from 4.1.0 to 4.1.1.
- [Release notes](https://github.com/kornelski/http-cache-semantics/releases)
- [Commits](https://github.com/kornelski/http-cache-semantics/compare/v4.1.0...v4.1.1)

---
updated-dependencies:
- dependency-name: http-cache-semantics
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-03-02 10:41:13 -05:00
f92b50e9ee
v2.0.2 2022-02-12 09:43:16 -05:00
51e8e0161f
bump all deps (and fix security warning from devDependencies) 2022-02-12 09:41:32 -05:00
b181818b02
run tests on node 17.x 2021-10-20 10:29:03 -04:00
ae885be192
v2.0.1 2021-10-16 09:55:44 -04:00
9454810eab
fs.exists() (deprecated) -> fs.access() 2021-10-16 09:53:32 -04:00
efbca27fd0
correct an irrelevant detail in mocha tests 2021-10-16 07:17:19 -04:00
8 changed files with 402 additions and 581 deletions

View File

@ -16,19 +16,21 @@ jobs:
- macos-latest
- windows-latest
node:
- 20
- 18
- 16
- 14
- 12
fail-fast: false
runs-on: ${{ matrix.os }}
name: Node ${{ matrix.node }} on ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
- run: yarn install --frozen-lockfile
- run: yarn audit
continue-on-error: true
- run: yarn test
env:
DEBUG: careful-downloader

View File

@ -10,10 +10,10 @@ jobs:
name: Publish to NPM
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 14
node-version: 18
registry-url: https://registry.npmjs.org/
- env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

1
.gitignore vendored
View File

@ -3,3 +3,4 @@ node_modules/
# potentially leftover test artifacts
downloads/
test/temp/
*.log

View File

@ -1,6 +1,6 @@
import path from "path";
import fs from "fs-extra";
import tempy from "tempy";
import { temporaryDirectory } from "tempy";
import decompress from "decompress";
import isPathInside from "is-path-inside";
@ -47,7 +47,7 @@ export default async (downloadUrl, options) => {
}
// initialize temporary directory
const tempDir = tempy.directory();
const tempDir = temporaryDirectory();
debug(`Temp dir generated: '${tempDir}'`);
try {
@ -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]+[*]?(.+)$/;

View File

@ -1,6 +1,6 @@
{
"name": "careful-downloader",
"version": "2.0.0",
"version": "3.0.0",
"description": "🕵️‍♀️ Downloads a file and its checksums, validates the hash, and optionally extracts it if safe.",
"license": "MIT",
"homepage": "https://github.com/jakejarvis/careful-downloader",
@ -25,24 +25,24 @@
"test": "eslint . && mocha"
},
"dependencies": {
"debug": "^4.3.2",
"debug": "^4.3.4",
"decompress": "^4.2.1",
"fs-extra": "^10.0.0",
"got": "^11.8.2",
"fs-extra": "^11.1.1",
"got": "^12.6.0",
"is-path-inside": "^4.0.0",
"tempy": "^2.0.0"
"tempy": "^3.0.0"
},
"devDependencies": {
"@jakejarvis/eslint-config": "*",
"@types/debug": "^4.1.7",
"@types/debug": "^4.1.8",
"@types/decompress": "^4.2.4",
"@types/fs-extra": "^9.0.13",
"chai": "^4.3.4",
"eslint": "^8.0.1",
"mocha": "^9.1.3"
"@types/fs-extra": "^11.0.1",
"chai": "^4.3.7",
"eslint": "^8.41.0",
"mocha": "^10.2.0"
},
"engines": {
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
"node": ">=14.14"
},
"keywords": [
"download",

View File

@ -42,7 +42,7 @@ describe("checksum via downloaded text file", function () {
},
)).to.throw;
expect(fs.existsSync(path.join(__dirname, "temp", "hugo.exe"))).to.be.false;
expect(fs.existsSync(path.join(__dirname, "temp", "hugo_0.88.0_Windows-64bit.zip"))).to.be.false;
// clean up
fs.removeSync(path.join(__dirname, "temp"));
@ -101,7 +101,7 @@ describe("checksum via string", function () {
this.timeout(30000); // increase timeout to an excessive 30 seconds for CI
expect(async () => download(
// download mismatching versions to trigger error
// validate against a clearly incorrect hash
"https://github.com/gohugoio/hugo/releases/download/v0.88.0/hugo_0.88.0_Windows-64bit.zip",
{
checksumHash: "abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234",
@ -111,7 +111,7 @@ describe("checksum via string", function () {
},
)).to.throw;
expect(fs.existsSync(path.join(__dirname, "temp", "hugo.exe"))).to.be.false;
expect(fs.existsSync(path.join(__dirname, "temp", "hugo_0.88.0_Windows-64bit.zip"))).to.be.false;
// clean up
fs.removeSync(path.join(__dirname, "temp"));

926
yarn.lock

File diff suppressed because it is too large Load Diff