An open API service indexing awesome lists of open source software.

https://github.com/patitotective/downit

Asynchronous downloads manager library for Nim.
https://github.com/patitotective/downit

asynchronous download-manager nim nim-lang

Last synced: 22 days ago
JSON representation

Asynchronous downloads manager library for Nim.

Awesome Lists containing this project

README

        

# DownIt
Asynchronous downloads and requests manager library for Nim.

```
nimble install downit
```

## Usage
The `Downloader` object holds all the downloads data, `initDownloader` takes the root directory for all the downloads (or `""` if none), the poll timeout (by default 1 ms), and optionally a proxy, an username and a password for the proxy (you can change the proxy always using `setProxy` or `removeProxy`).
After initializing it, downloading something it's just as easy as calling `download`, procedure that takes the url, path and an optional name, if not given the path will be the name. Setting a name is useful to identify a download and makes changing the path a lot easier.
You can also make a GET request using the `request` procedure, passing the url and optionally a name.
After making a download/request you can use the `running`, `succeed`, `finished` and `failed` procedures to check wheter a download/request finished, is still in progress or failed.
```nim
var downloader = initDownloader("./docs") # We could add proxy = "http://127.0.0.1:8888"
downloader.download("https://nim-lang.org/docs/os.html", "os.html", "os")
downloader.request("https://nim-lang.org/docs/strformat.html", "strformat")

while true:
downloader.update() # Poll events and check if downloads are complete

if downloader.succeed("os") and downloader.succeed("strformat"):
echo readFile(downloader.getPath("os").get())
echo downloader.getBody("strformat").get()
break

elif downloader.getError("os").isSome: # You can also do downloader.getState("os").get() == DownloadError
raise downloader.getError("os").get()
```
Remember to compile with `-d:ssl`.

Read more at the [docs](https://patitotective.github.io/downit)

## About
- GitHub: https://github.com/Patitotective/downit.
- Discord: https://discord.gg/U23ZQMsvwc.

Contact me:
- Discord: **Patitotective#0127**.
- Twitter: [@patitotective](https://twitter.com/patitotective).
- Email: **[email protected]**.