diff options
Diffstat (limited to 'mystringlistunit.pas')
-rw-r--r-- | mystringlistunit.pas | 22 |
1 files changed, 16 insertions, 6 deletions
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; |