summaryrefslogtreecommitdiff
path: root/mystringlistunit.pas
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2015-11-17 16:25:23 +0100
committerErich Eckner <git@eckner.net>2015-11-17 16:25:23 +0100
commit6e6e957909e2729b01d827f44a095bc2936a36ad (patch)
treea92d70a19831a6953cd55b4484d23b600ec2b582 /mystringlistunit.pas
parent61a6a63a16e092881a42aeb6ca91c091b2ad6b1c (diff)
downloadunits-6e6e957909e2729b01d827f44a095bc2936a36ad.tar.xz
tMyStringList speichert nun nicht mehr in situ
Diffstat (limited to 'mystringlistunit.pas')
-rw-r--r--mystringlistunit.pas22
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;