# filedljs

> A small utility library for downloading files from the web, while providing a progress reporting

Latest version **0.1.3** (published 2018-10-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install filedljs
pnpm add filedljs
yarn add filedljs
bun add filedljs
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.3 |
| Published | 2018-10-16 |
| First published | 2018-09-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 17.1 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Wael Hasan |
| Maintainers | whasan |
| Keywords | download, file, web |

## Links

- npm: https://www.npmjs.com/package/filedljs
- Repository: https://github.com/waelhasan/filedljs
- Issues: https://github.com/waelhasan/filedljs/issues
- npm.io page: https://npm.io/package/filedljs

## Dependencies (3)

- [request](https://npm.io/package/request.md) ^2.88.0
- [shelljs](https://npm.io/package/shelljs.md) ^0.8.2
- [request-progress](https://npm.io/package/request-progress.md) ^3.0.0

## Alternatives

- [unionfs](https://npm.io/package/unionfs.md) — 2.2M weekly downloads
- [path-starts-with](https://npm.io/package/path-starts-with.md) — 35.9K weekly downloads
- [redzip](https://npm.io/package/redzip.md) — 1.2K weekly downloads
- [vscode-anymatch](https://npm.io/package/vscode-anymatch.md) — 848 weekly downloads
- [@ledgerhq/coin-filecoin](https://npm.io/package/@ledgerhq/coin-filecoin.md) — 793 weekly downloads

## Recent versions

- 0.1.3 (latest) — 2018-10-16
- 0.1.2 — 2018-10-15
- 0.1.1 — 2018-09-21
- 0.1.0 — 2018-09-21
- 1.0.0 — 2018-09-21

## README

# filedljs (file download js)
A small utility library for downloading files from the web, providing the following features:
- Accepts an onProgress callback, which receives a state object to indicate the progress of the downloading
- Automatically monitor the download, and abort it if it is halted for a specific period (configurable)
- Delete file if download didn't complete successfully (configurable)
- Automatically retry downloading the file if something went wrong, and the maximum number of download attempts is configurable

### Installing

Clone using git 
```
git clone  https://github.com/waelhasan/filedljs.git  filedljs
cd filedljs/
npm install
```
Install with npm
```
npm install --save filedljs
```

### Testing

```
npm test
```

### Usage

```js
const { downloadFile } = require('filedljs');
const logProgress = require('./logProgress')

downloadFile(
    <file_path>, // optional
    <file_url>,
    <options_object> // optional
)
    .then(() => {})
    .catch(error => {})

```

### Examples

- Using the original name of the file, and specifying the download folder

```js
const { downloadFile } = require('filedljs');
const logProgress = require('./logProgress')

downloadFile(
    'http://file.allitebooks.com/20180714/React%20in%20Action.pdf',
    {
        baseDir: './files'
    }
)
    .then(() => console.log('[!!!] END OF DOWNLOAD'))
    .catch(error => console.log('[x] ERROR DOWNLOADING', error))

```

- Specifying the full path and file name

```js
downloadFile(
    './files/test.pdf',
    'http://file.allitebooks.com/20180714/React%20in%20Action.pdf',
    {
        onProgress: (state) => logProgress(state)
    }
)

```

- Prevent deleting the file if the download didn't complete (default: true)

```js
downloadFile(
    'http://file.allitebooks.com/20180714/React%20in%20Action.pdf',
    {
        deleteIfLessSize: false
    }
)
```

- Specify the maximum allowed time for download halt (default: 1 minute)

```js
downloadFile(
    'http://file.allitebooks.com/20180714/React%20in%20Action.pdf',
    {
        downloadHaltMaxTime: 2 * 60 * 1000, // in milliseconds
    }
)
```

- Prevent creating the file path if it doesn't exist (default: true)

```js
downloadFile(
    'http://file.allitebooks.com/20180714/React%20in%20Action.pdf',
    {
        createPathIfNotExist: false
    }
)
```

- Automatically retry downloading the file for 3 times

```js
downloadFile(
    'http://file.allitebooks.com/20180714/React%20in%20Action.pdf',
    {
        maxِAttempts: 3
    }
)
```

- Using all default values

```js
downloadFile('http://file.allitebooks.com/20180714/React%20in%20Action.pdf')
```

### Default options:

These are the default values of the option object fields:

```js
const defaultOptions = {
    baseDir: '.',
    createPathIfNotExist: true,
    downloadHaltMaxTime: 1 * 60 * 1000,
    onProgress: function () { },
    deleteIfLessSize: true,
    maxِAttempts: 2
};
```

### Todo:

- Add more tests:
    - unit tests 
    - testing the download functionality (mocking the network)
    - testing ProgressMonitor (mocking timers)
- Add proper comments

## Authors

* **Wael Hasan** - [waelhasan](https://github.com/waelhasan)

## Contributors
* **M4rk9696** - [M4rk9696](https://github.com/M4rk9696)
Added some unit tests

## License

This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details

---
_Source: https://npm.io/package/filedljs · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
