iex -S mix # In a project with HTTPotion in mix.exs.
iex(1)> ProgressiveDownloader.run
Let's download 43.2 MB…
2.31% (1.0 MB)
4.63% (2.0 MB)
6.94% (3.0 MB)
9.26% (4.0 MB)
11.57% (5.0 MB)
13.89% (6.0 MB)
16.2% (7.0 MB)
18.52% (8.0 MB)
20.83% (9.0 MB)
23.15% (10.0 MB)
25.46% (11.0 MB)
27.78% (12.0 MB)
30.09% (13.0 MB)
32.4% (14.0 MB)
34.72% (15.0 MB)
37.03% (16.0 MB)
39.35% (17.0 MB)
41.66% (18.0 MB)
43.98% (19.0 MB)
46.29% (20.0 MB)
48.61% (21.0 MB)
50.92% (22.0 MB)
53.24% (23.0 MB)
55.55% (24.0 MB)
57.87% (25.0 MB)
60.18% (26.0 MB)
62.49% (27.0 MB)
64.81% (28.0 MB)
67.12% (29.0 MB)
69.44% (30.0 MB)
71.75% (31.0 MB)
74.07% (32.0 MB)
76.38% (33.0 MB)
78.7% (34.0 MB)
81.01% (35.0 MB)
83.33% (36.0 MB)
85.64% (37.0 MB)
87.96% (38.0 MB)
90.27% (39.0 MB)
92.58% (40.0 MB)
94.9% (41.0 MB)
97.21% (42.0 MB)
99.53% (43.0 MB)
100.0% (43.2 MB)
All downloaded! See: /tmp/posture.mp4
CARVIEW |
Select Language
HTTP/2 200
date: Thu, 31 Jul 2025 00:25:39 GMT
content-type: text/html; charset=utf-8
vary: X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, X-Requested-With,Accept-Encoding, Accept, X-Requested-With
etag: W/"2206bc731f3276c45393d7f882b7be18"
cache-control: max-age=0, private, must-revalidate
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 0
referrer-policy: origin-when-cross-origin, strict-origin-when-cross-origin
content-security-policy: default-src 'none'; base-uri 'self'; child-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com *.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com wss://alive-staging.github.com api.githubcopilot.com api.individual.githubcopilot.com api.business.githubcopilot.com api.enterprise.githubcopilot.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com private-avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com release-assets.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com copilotprodattachments.blob.core.windows.net/github-production-copilot-attachments/ github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/
server: github.com
content-encoding: gzip
accept-ranges: bytes
set-cookie: _gh_sess=niKYiOGSFQO8HOiux15o%2F1QDeNwYRhu%2BR%2Bl3PUzLKIK7wkaxoDRbiCsJPxqio5zKAVWasW3sYiPboSQoTIkqCxhxyvab2MeV33dm5p%2FY0LmK1hz8Yjgjh7Rx5oLE9JXYJ80m4%2Fw9h6AVXVpyqgAAxyb1QuoIAe9j73768JJOWyH8TpP%2Br%2BJiUV26IlT37y96VUFCIAKMF1BG%2BFON3ANHPld%2BiWlhJqI5I9ss43VAQHtUNbY8jRWnCk58V68ex%2BzRaxAV7AJsScApYwzAqr1xng%3D%3D--AAG8ESv3xlE%2BtT1c--99B9oEP814B%2BGrmzSrDH0A%3D%3D; Path=/; HttpOnly; Secure; SameSite=Lax
set-cookie: _octo=GH1.1.822546603.1753921539; Path=/; Domain=github.com; Expires=Fri, 31 Jul 2026 00:25:39 GMT; Secure; SameSite=Lax
set-cookie: logged_in=no; Path=/; Domain=github.com; Expires=Fri, 31 Jul 2026 00:25:39 GMT; HttpOnly; Secure; SameSite=Lax
x-github-request-id: BBF2:144580:F3289:16E9EB:688AB803
Example of progressive downloading with HTTPotion, showing percentage and downloaded bytes as you go. · GitHub
Show Gist options
Save henrik/108e5fc23b66131fc3aa to your computer and use it in GitHub Desktop.
{{ message }}
Instantly share code, notes, and snippets.
Last active
December 4, 2020 05:41
-
Star
13
(13)
You must be signed in to star a gist -
Fork
0
(0)
You must be signed in to fork a gist
-
Save henrik/108e5fc23b66131fc3aa to your computer and use it in GitHub Desktop.
Example of progressive downloading with HTTPotion, showing percentage and downloaded bytes as you go.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule ProgressiveDownloader do | |
def run do | |
url = "https://ia600308.us.archive.org/2/items/HealthYo1953/HealthYo1953_512kb.mp4" | |
HTTPotion.get url, stream_to: self, timeout: :infinity | |
receive_data(total_bytes: :unknown, data: "") | |
end | |
defp receive_data(total_bytes: total_bytes, data: data) do | |
receive do | |
%HTTPotion.AsyncHeaders{headers: h} -> | |
{total_bytes, _} = h[:"Content-Length"] |> Integer.parse | |
IO.puts "Let's download #{mb total_bytes}…" | |
receive_data(total_bytes: total_bytes, data: data) | |
%HTTPotion.AsyncChunk{chunk: new_data} -> | |
accumulated_data = data <> new_data | |
accumulated_bytes = byte_size(accumulated_data) | |
percent = accumulated_bytes / total_bytes * 100 |> Float.round(2) | |
IO.puts "#{percent}% (#{mb accumulated_bytes})" | |
receive_data(total_bytes: total_bytes, data: accumulated_data) | |
%HTTPotion.AsyncEnd{} -> | |
path = "/tmp/posture.mp4" | |
File.write!(path, data) | |
IO.puts "All downloaded! See: #{path}" | |
end | |
end | |
defp mb(bytes) do | |
number = bytes / 1_048_576 |> Float.round(2) | |
"#{number} MB" | |
end | |
end |
I tried to use this snippet, but apparently there's something wrong with HTTPotion at some point:
iex(1)⋅❯ ProgressiveDownloader.run
** (Protocol.UndefinedError) protocol List.Chars not implemented for #PID<0.139.0>
(elixir) lib/list/chars.ex:1: List.Chars.impl_for!/1
(elixir) lib/list/chars.ex:12: List.Chars.to_char_list/1
lib/httpotion.ex:157: anonymous fn/1 in HTTPotion.request/5
(elixir) lib/enum.ex:1043: anonymous fn/3 in Enum.map/2
(elixir) lib/enum.ex:1385: Enum."-reduce/3-lists^foldl/2-0-"/3
(elixir) lib/enum.ex:1043: Enum.map/2
lib/httpotion.ex:157: HTTPotion.request/5
(sploit) lib/1-progressive_downloader.ex:5: ProgressiveDownloader.run/0
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can’t perform that action at this time.
Combine with https://gist.github.com/henrik/b950bfd7fa432eacd902 for a progress bar.
See it in action in https://github.com/henrik/sipper.