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.
- Host: GitHub
- URL: https://github.com/patitotective/downit
- Owner: Patitotective
- License: mit
- Created: 2022-06-16T01:39:11.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-01-12T00:43:17.000Z (over 1 year ago)
- Last Synced: 2025-03-30T19:37:03.813Z (about 2 months ago)
- Topics: asynchronous, download-manager, nim, nim-lang
- Language: Nim
- Homepage: https://patitotective.github.io/downit
- Size: 149 KB
- Stars: 12
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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 completeif downloader.succeed("os") and downloader.succeed("strformat"):
echo readFile(downloader.getPath("os").get())
echo downloader.getBody("strformat").get()
breakelif 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]**.