-
-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Part Downloads #133
Comments
Can you please elaborate on the problem? |
If you lose your internet connection in the middle then there are times the downloads are not resumed but restarted. |
I understand. I will look into this. |
I have looked into it, and it seems quite easy to implement: we pass the Here's a snipped to play with. I'm not a HTTP expert, but it looks okay to me. I did ctrl+c and restarted several times and still got full zip file downloaded. If noone sees any issues, I can add that to haxelib. import haxe.io.Output;
import sys.io.File;
class Main {
static function main() {
var url = "http://lib.haxe.org/files/3.0/lime-2,0,0-alpha,8.zip";
var f = File.append("lime.zip", true);
f.seek(0, SeekEnd);
var h = new haxe.Http(url);
var cur = f.tell();
if (cur > 0)
h.addHeader("range", "bytes="+cur + "-");
h.customRequest(false, new Progress(f, cur));
}
}
class Progress extends Output {
var o : Output;
var cursize : Int;
var cur : Int;
var max : Int;
public function new(o, cursize) {
this.o = o;
this.cursize = cursize;
this.cur = cursize;
}
function report(n) {
cur += n;
if( max == null )
Sys.print(cur+" bytes\r");
else
Sys.print(cur+"/"+max+" ("+Std.int((cur*100.0)/max)+"%)\r");
}
public override function writeByte(c) {
o.writeByte(c);
report(1);
}
public override function writeBytes(s,p,l) {
var r = o.writeBytes(s,p,l);
report(r);
return r;
}
public override function close() {
super.close();
o.close();
Sys.println("Download complete : "+cur+" bytes");
}
public override function prepare(m:Int) {
max = m + cursize;
}
} |
Looks good to me, just have to make sure that when the complete file is downloaded but is corrupted/incorrect it's deleted in order to not get stuck. |
Is it possible to ensure partly downloaded files are not downloaded from the start.
The text was updated successfully, but these errors were encountered: