Delphi - MemoryStream or FileStream -
i downloading exe file internet using indy (idhttp), , can use memorystream or filestream save disk, not know if there difference between them (maybe in result structure of file?). could't find yet answer this.
where, here 2 simple functions simulate doing:
function downloadms(furl, dest: string): boolean; var http: tidhttp; strm: tmemorystream; begin result := false; http := tidhttp.create; strm := tmemorystream.create; http, strm try try get(furl, strm); if (size > 0) begin position := 0; savetofile(dest); result := true; end; except end; strm.free; http.free; end; end; function downloadfs(furl, dest: string): boolean; var http: tidhttp; strm: tfilestream; begin result := false; http := tidhttp.create; strm := tfilestream.create(dest, fmcreate); http, strm try try get(furl, strm); result := (size > 0); except end; strm.free; http.free; end; end;
what experts think using 1 or other type (memorystream or filestream)? there difference in structure of exe file when using 1 or other type? type recommended?
thank you! have nice weekend!
there no difference between tmemorystream
or tfilestream
stream point of view.
they both streams , hold stream of bytes , both derived tstream
.
you can implement function generalized this
function downloadtostream( const aurl : string; adest : tstream ): boolean; var lhttp: tidhttp; begin lhttp := tidhttp.create; try lhttp.get( aurl, adest ); result := adest.size > 0; lhttp.free; end; end;
and call tfilestream
var lstream : tstream; begin lstream := tfilestream.create( 'myfile.exe', fmcreate ); if downloadtostream( '', lstream ) ... end;
or tmemorystream
or whatever stream instance like
Comments
Post a Comment