haXe Forum > haXe - PHP - Http.onProgress
-
Karsten John Gerber Feb 03 at 15:31
Hi All!
I'm new to the haXe-thing, be i like it so far.
I am playing around with it at the moment and i tried to build a small Download-Manager using neko. And therefor i wanted to display the progress of the download. Since i could not find something like haxe.Http.onProgress i wrote the additional code i needed into the class. It's not much, but it was fun and easy to figure out, what to do.
Now my questions:
1) Does any one want to see, what i did in the haxe.Http-class?
2) How can i contribute in developping the haxe-classes, since it would like to?
3) Is there a roadmap for the development?And here is what i did:
public dynamic function onProgress( bytesRead : Int, bytesTotal : Int ) { }
and then changed the Http.readHttpResponse method to:
function readHttpResponse( api : haxe.io.Output, sock : AbstractSocket ) { ... var bytesRead = 0; var bytesTotal = size; if( size == null ) { if( !noShutdown ) sock.shutdown(false,true); try { while( true ) { var len = sock.input.readBytes(buf,0,bufsize); if( chunked ) { if( !readChunk(chunk_re,api,buf,len) ) break; } else { api.writeBytes(buf, 0, len); bytesRead += len; onProgress(bytesRead, null); } } } catch( e : haxe.io.Eof ) { } } else { api.prepare(size); try { while( size > 0 ) { var len = sock.input.readBytes(buf,0,if( size > bufsize ) bufsize else size); if( chunked ) { if( !readChunk(chunk_re,api,buf,len) ) break; } else { api.writeBytes(buf, 0, len); bytesRead += len; onProgress(bytesRead, bytesTotal); } size -= len; } } catch( e : haxe.io.Eof ) { throw "Transfert aborted"; } } ... }
So one can use it like:
var http = new Http(url); http.onProgress = function(bytesRead : Int, bytesTotal : Int) { neko.Lib.println("onProgress bytesRead " + bytesRead + " / " + bytesTotal); }; http.request(false);
So what do you guys think?
Greeting from Germany,
Karsten Gerber -
contribute_to_haxe anything posted on the haXe issue list will appear on the mailing list, additional functionality is more likely to make it into haxe, if developed for cross platform. You may need to look at Conditional Compilation switches for code to work across different languages. Often new functionality is added via haxeLib rather than directly to the core where new functionality is limited to keep stability, but with features such as Using, its often does not matter if code is implemented via a haXeLib or a base class. Some haXeLib classes and methods move to haXe base classes with time if they are deemed essential and proven.