{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "89fe6b40", "metadata": {}, "outputs": [], "source": [ "# default_exp core" ] }, { "cell_type": "markdown", "id": "3f88277e", "metadata": {}, "source": [ "# Core API" ] }, { "cell_type": "code", "execution_count": null, "id": "9e4b351a", "metadata": {}, "outputs": [], "source": [ "# export\n", "from fastprogress.fastprogress import progress_bar\n", "from fastcore.all import *\n", "import hashlib,shutil\n", "from pprint import pformat" ] }, { "cell_type": "code", "execution_count": null, "id": "26a28dbd", "metadata": {}, "outputs": [], "source": [ "#hide\n", "from nbdev.showdoc import show_doc\n", "import tempfile,fastdownload" ] }, { "cell_type": "markdown", "id": "37ccd175", "metadata": {}, "source": [ "## Helpers" ] }, { "cell_type": "markdown", "id": "31596f8a", "metadata": {}, "source": [ "This helper functions provide the functionality that `FastDownload` relies on. Most users should use `FastDownload` rather than calling these helpers." ] }, { "cell_type": "code", "execution_count": null, "id": "5087e93f", "metadata": {}, "outputs": [], "source": [ "dest = Path('tmp')\n", "url = 'https://s3.amazonaws.com/fast-ai-sample/mnist_tiny.tgz'" ] }, { "cell_type": "code", "execution_count": null, "id": "6ddb7048", "metadata": {}, "outputs": [], "source": [ "#hide\n", "shutil.rmtree(dest, ignore_errors=True)\n", "Path.BASE_PATH = Path.home()" ] }, { "cell_type": "code", "execution_count": null, "id": "171df7b7", "metadata": {}, "outputs": [], "source": [ "#export\n", "def download_url(url, dest=None, timeout=None, show_progress=True):\n", " \"Download `url` to `dest` and show progress\"\n", " pbar = progress_bar([])\n", " def progress(count=1, bsize=1, tsize=None):\n", " pbar.total = tsize\n", " pbar.update(count*bsize)\n", " return urlsave(url, dest, reporthook=progress if show_progress else None, timeout=timeout)" ] }, { "cell_type": "code", "execution_count": null, "id": "7387f086", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
FastDownload.download
[source]FastDownload.download
(**`url`**, **`force`**=*`False`*)\n",
"\n",
"Download `url` to archive path, unless exists and `self.check` fails and not `force`"
],
"text/plain": [
"FastDownload.update
[source]FastDownload.update
(**`url`**)\n",
"\n",
"Store the hash and size in `download_checks.py`"
],
"text/plain": [
"FastDownload.extract
[source]FastDownload.extract
(**`url`**, **`extract_key`**=*`'data'`*, **`force`**=*`False`*)\n",
"\n",
"Extract archive already downloaded from `url`, overwriting existing if `force`"
],
"text/plain": [
"FastDownload.rm
[source]FastDownload.rm
(**`url`**, **`rm_arch`**=*`True`*, **`rm_data`**=*`True`*, **`extract_key`**=*`'data'`*)\n",
"\n",
"Delete downloaded archive and extracted data for `url`"
],
"text/plain": [
"FastDownload.get
[source]FastDownload.get
(**`url`**, **`extract_key`**=*`'data'`*, **`force`**=*`False`*)\n",
"\n",
"Download and extract `url`, overwriting existing if `force`"
],
"text/plain": [
"