diff options
Diffstat (limited to 'etc/get.lua')
-rw-r--r-- | etc/get.lua | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/etc/get.lua b/etc/get.lua index 33da653..af46c16 100644 --- a/etc/get.lua +++ b/etc/get.lua | |||
@@ -1,3 +1,7 @@ | |||
1 | ----------------------------------------------------------------------------- | ||
2 | -- Little program to download files from URLs | ||
3 | -- LuaSocket 1.5 sample files | ||
4 | ----------------------------------------------------------------------------- | ||
1 | -- formats a number of seconds into human readable form | 5 | -- formats a number of seconds into human readable form |
2 | function nicetime(s) | 6 | function nicetime(s) |
3 | local l = "s" | 7 | local l = "s" |
@@ -63,15 +67,15 @@ function receive2disk(file, size) | |||
63 | size = size | 67 | size = size |
64 | } | 68 | } |
65 | local receive_cb = function(chunk, err) | 69 | local receive_cb = function(chunk, err) |
66 | local dt = socket._time() - %aux.start -- elapsed time since start | 70 | local dt = socket._time() - aux.start -- elapsed time since start |
67 | if not chunk or chunk == "" then | 71 | if not chunk or chunk == "" then |
68 | io.write("\n") | 72 | io.write("\n") |
69 | aux.file:close() | 73 | aux.file:close() |
70 | return | 74 | return |
71 | end | 75 | end |
72 | aux.file:write(chunk) | 76 | aux.file:write(chunk) |
73 | aux.got = aux.got + string.len(chunk) -- total bytes received | 77 | aux.got = aux.got + string.len(chunk) -- total bytes received |
74 | if dt < 0.1 then return 1 end -- not enough time for estimate | 78 | if dt < 0.1 then return 1 end -- not enough time for estimate |
75 | io.write("\r", gauge(aux.got, dt, aux.size)) | 79 | io.write("\r", gauge(aux.got, dt, aux.size)) |
76 | return 1 | 80 | return 1 |
77 | end | 81 | end |
@@ -122,7 +126,7 @@ function getschemeandname(url, name) | |||
122 | return parsed.scheme, name | 126 | return parsed.scheme, name |
123 | end | 127 | end |
124 | 128 | ||
125 | -- gets a file either by http or url, saving as name | 129 | -- gets a file either by http or ftp, saving as <name> |
126 | function get(url, name) | 130 | function get(url, name) |
127 | local scheme | 131 | local scheme |
128 | scheme, name = getschemeandname(url, name) | 132 | scheme, name = getschemeandname(url, name) |