[REBOL] tired of broken downloads?
From: petr::krenzelok::trz::cz at: 16-Aug-2002 7:57
Hello,
in the age of advanced Internet browsers, we still can meet with very
lame downloaders they provide. They offer no ability to start at the
place where download was broken. So I created following 1KB in size
small util. As you can see - no GUI. I tried, but I spent most of my
time playing with look, so I gave up. It is simple, small, does what it
is supposed to do, well, mostly.
Every time I think I finally understand how something works, I stay
starving at console, getting unexpected results. So, the script as it is
seems to work. Just try to answer my following questions:
1) I tried to use simply "data: copy source" aproach. The strange thing
is, that while I use /no-wait, it should perform body block of 'while.
But I can see console hanging, and the body block is entered only once -
once file is completly downloaded. But - 'copy should not block here, no?
2) With larger file, I obtain network time-out. So I tried to use some
kind of "not error? try [data: copy source]", but well, once port is
closed by the other side, 'none is generated, but 'none itself doesn't
return false(error) state to 'try. So - how to adapt the script, so I
could safely go home, and let my script to
download-damned-thing-even-in-million-pieces, safely? :-)
... I turned it back to copy/part aproach, but - is open/no-wait on http
port broken? Why does 'copy block, or - what happens at all? Any
explanation appreciated.
PS: used write/binary/append, untill open/skip works as expected ....
-pekr-
-------------------------------
REBOL []
source-url: http://www.rebol.cz/~cyphre/
source-file: %styles2.jpg
target-path: %./
target-file: source-file
source-size: size? join source-url source-file
either exists? join target-path target-file [
target-size: size? join target-path target-file
][target-size: 0]
if target-size == source-size [print "Nothing to download, file already
complete ..." halt]
if target-size > 0 [print ["Appending at " target-size "bytes"]]
start: now/time
forever [
while [error? try [source: open/binary/direct/no-wait/skip join
source-url source-file target-size]][
print "Can't open source file .... waiting 10 min"
wait 00:10
]
while [
wait source
data: copy/part source 2048
][
write/binary/append join target-path target-file data
target-size: target-size + length? data
print ["Source-size: " source-size tab "Downloaded: " target-size
tab "Time: " now/time - start]
]
if target-size >= source-size [break]
]
close source