From 6e6e957909e2729b01d827f44a095bc2936a36ad Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Tue, 17 Nov 2015 16:25:23 +0100 Subject: tMyStringList speichert nun nicht mehr in situ --- mystringlistunit.pas | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'mystringlistunit.pas') diff --git a/mystringlistunit.pas b/mystringlistunit.pas index 0895781..f67d117 100644 --- a/mystringlistunit.pas +++ b/mystringlistunit.pas @@ -153,14 +153,19 @@ end; procedure tMyStringlist.saveToGz(const s: ansiString); var - p: tProcess; - buf: array of byte; - f: file; - rb: longint; - it: tInputThread; + p: tProcess; + buf: array of byte; + f: file; + rb: longint; + it: tInputThread; + datNam: string; const outBufLen = 1024*1024; begin + if fileexists(s) then + datNam:=mkTemp(s+'.XXXXXX') + else + datNam:=s; p:=tProcess.create(nil); p.executable:='/usr/bin/gzip'; p.parameters.add('--best'); @@ -170,7 +175,7 @@ begin setlength(buf,outBufLen); fillchar(buf[0],length(buf)*sizeof(buf[0]),$0); it:=tInputThread.create(p,self); - assignfile(f,s); + assignfile(f,datNam); rewrite(f,1); while p.running or (not it.fertig) or (p.output.numBytesAvailable>0) do begin rb:=min(length(buf),p.output.numBytesAvailable); @@ -181,8 +186,13 @@ begin else sleep(1); // nix zu Schreiben, nix zu Lesen, also warten wir end; + p.free; it.free; closefile(f); + if s<>datNam then begin + deleteFile(s); + rename(f,s); + end; end; function tMyStringlist.readln(out s: string): boolean; -- cgit v1.2.3-70-g09d2