Skip to content

Commit e375790

Browse files
committed
Merge branch 'HealthIntersections-master' into linuxscripts
2 parents e936e4e + 2877ab8 commit e375790

File tree

10 files changed

+569
-307
lines changed

10 files changed

+569
-307
lines changed

dependencies/zflate/zflate.pas

+83-20
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
interface
3333

3434
uses
35-
SysUtils, ZBase, ZInflate, ZDeflate;
35+
ZBase, ZInflate, ZDeflate;
3636

3737
type
3838
tzflate = record
@@ -56,7 +56,7 @@ tgzipinfo = record
5656
footerlen: dword;
5757
end;
5858

59-
Tristate = (tNull, tTrue, tFalse);
59+
TBytes = array of byte;
6060

6161
const
6262
ZFLATE_ZLIB = 1;
@@ -107,10 +107,14 @@ function zfindstream(data: pointer; size: dword; var streamtype: dword; var star
107107
function gzdeflate(data: pointer; size: dword; var output: pointer; var outputsize: dword; level: dword=9): boolean;
108108
//compress whole string to DEFLATE at once
109109
function gzdeflate(str: string; level: dword=9): string;
110+
//compress whole bytes to DEFLATE at once
111+
function gzdeflate(bytes : TBytes; level: dword=9): TBytes;
110112
//decompress whole DEFLATE buffer at once
111113
function gzinflate(data: pointer; size: dword; var output: pointer; var outputsize: dword): boolean;
112114
//decompress whole DEFLATE string at once
113115
function gzinflate(str: string): string;
116+
//decompress whole DEFLATE bytes at once
117+
function gzinflate(bytes : TBytes): TBytes;
114118

115119
//make ZLIB header
116120
function makezlibheader(compressionlevel: integer): string;
@@ -120,14 +124,14 @@ function makezlibfooter(adler: dword): string;
120124
function gzcompress(data: pointer; size: dword; var output: pointer; var outputsize: dword; level: dword=9): boolean;
121125
//compress whole string to ZLIB at once
122126
function gzcompress(str: string; level: dword=9): string;
127+
//compress whole buffer to ZLIB at once
128+
function gzcompress(bytes : TBytes; level: dword=9) : TBytes;
123129
//dempress whole ZLIB buffer at once !
124-
function gzuncompress(data: pointer; size: dword; readHeader : Tristate; var output: pointer; var outputsize: dword): boolean;
130+
function gzuncompress(data: pointer; size: dword; var output: pointer; var outputsize: dword): boolean;
125131
//dempress whole ZLIB string at once
126132
function gzuncompress(str: string): string;
127-
//compress whole buffer to ZLIB at once
128-
function gzcompress(bytes : TBytes; level: dword=9) : TBytes;
129133
//dempress whole ZLIB buffer at once
130-
function gzuncompress(bytes : TBytes; readHeader : Tristate = tNull) : TBytes;
134+
function gzuncompress(bytes : TBytes) : TBytes;
131135

132136
//make GZIP header
133137
function makegzipheader(compressionlevel: integer; filename: string=''; comment: string=''): string;
@@ -137,15 +141,21 @@ function makegzipfooter(originalsize: dword; crc: dword): string;
137141
function gzencode(data: pointer; size: dword; var output: pointer; var outputsize: dword; level: dword=9; filename: string=''; comment: string=''): boolean;
138142
//compress whole string to GZIP at once
139143
function gzencode(str: string; level: dword=9; filename: string=''; comment: string=''): string;
144+
//compress whole string to GZIP at once
145+
function gzencode(bytes: TBytes; level: dword=9; filename: string=''; comment: string=''): TBytes;
140146
//decompress whole GZIP buffer at once
141147
function gzdecode(data: pointer; size: dword; var output: pointer; var outputsize: dword): boolean;
142148
//decompress whole GZIP string at once
143149
function gzdecode(str: string): string;
150+
//decompress whole GZIP string at once
151+
function gzdecode(bytes: TBytes): TBytes;
144152

145153
//try to detect buffer format and decompress it at once
146154
function zdecompress(data: pointer; size: dword; var output: pointer; var outputsize: dword): boolean;
147155
//try to detect string format and decompress it at once
148156
function zdecompress(str: string): string;
157+
//try to detect bytes format and decompress it at once
158+
function zdecompress(bytes: TBytes): TBytes;
149159

150160
//transalte error code to message
151161
function zflatetranslatecode(code: integer): string;
@@ -412,6 +422,18 @@ function gzdeflate(str: string; level: dword=9): string;
412422
freemem(p);
413423
end;
414424

425+
function gzdeflate(bytes: TBytes; level: dword=9): TBytes;
426+
var
427+
p: pointer;
428+
d: dword;
429+
begin
430+
result := nil;
431+
if not gzdeflate(@bytes[0], length(bytes), p, d, level) then exit;
432+
setlength(result, d);
433+
move(p^, result[0], d);
434+
freemem(p);
435+
end;
436+
415437
// -- inflate -----------------------------
416438

417439
function gzinflate(data: pointer; size: dword; var output: pointer; var outputsize: dword): boolean;
@@ -458,7 +480,19 @@ function gzinflate(str: string): string;
458480
result := '';
459481
if not gzinflate(@str[1], length(str), p, d) then exit;
460482
setlength(result, d);
461-
move(p^, result[1], d);
483+
move(p^, result[1], d);
484+
freemem(p);
485+
end;
486+
487+
function gzinflate(bytes: TBytes): TBytes;
488+
var
489+
p: pointer;
490+
d: dword;
491+
begin
492+
result := nil;
493+
if not gzinflate(@bytes[0], length(bytes), p, d) then exit;
494+
setlength(result, d);
495+
move(p^, result[0], d);
462496
freemem(p);
463497
end;
464498

@@ -544,29 +578,22 @@ function gzcompress(bytes : TBytes; level: dword=9) : TBytes;
544578

545579
// -- ZLIB decompress ---------------------
546580

547-
function gzuncompress(data: pointer; size: dword; readHeader : Tristate; var output: pointer; var outputsize: dword): boolean;
581+
function gzuncompress(data: pointer; size: dword; var output: pointer; var outputsize: dword): boolean;
548582
var
549583
zlib: tzlibinfo;
550584
z: tzflate;
551585
checksum: dword;
552-
header : boolean;
553586
begin
554587
result := false;
555-
header := false;
556-
if readHeader <> tFalse then
557-
if zreadzlibheader(data, zlib) then
558-
header := true
559-
else if readHeader = tTrue then
560-
exit(zerror(z, ZFLATE_EZLIBINVALID));
588+
if not zreadzlibheader(data, zlib) then exit(zerror(z, ZFLATE_EZLIBINVALID));
561589

562590
checksum := swapendian(pdword(data+size-4)^);
563591

564592
data += zlib.streamat;
565593
size -= zlib.streamat+zlib.footerlen;
566594
if not gzinflate(data, size, output, outputsize) then exit;
567595

568-
if header and (adler32(adler32(0, nil, 0), output, outputsize) <> checksum) then
569-
exit(zerror(z, ZFLATE_ECHECKSUM));
596+
if (adler32(adler32(0, nil, 0), output, outputsize) <> checksum) then exit(zerror(z, ZFLATE_ECHECKSUM));
570597

571598
result := true;
572599
end;
@@ -577,19 +604,19 @@ function gzuncompress(str: string): string;
577604
d: dword;
578605
begin
579606
result := '';
580-
if not gzuncompress(@str[1], length(str), tTrue, p, d) then exit;
607+
if not gzuncompress(@str[1], length(str), p, d) then exit;
581608
setlength(result, d);
582609
move(p^, result[1], d);
583610
freemem(p);
584611
end;
585612

586-
function gzuncompress(bytes : TBytes; readHeader : Tristate = tNull) : TBytes;
613+
function gzuncompress(bytes : TBytes) : TBytes;
587614
var
588615
p: pointer;
589616
d: dword;
590617
begin
591618
result := nil;
592-
if not gzuncompress(@bytes[0], length(bytes), readHeader, p, d) then exit;
619+
if not gzuncompress(@bytes[0], length(bytes), p, d) then exit;
593620
try
594621
setlength(result, d);
595622
move(p^, result[0], d);
@@ -686,6 +713,18 @@ function gzencode(str: string; level: dword=9; filename: string=''; comment: str
686713
freemem(p);
687714
end;
688715

716+
function gzencode(bytes: TBytes; level: dword=9; filename: string=''; comment: string=''): TBytes;
717+
var
718+
p: pointer;
719+
d: dword;
720+
begin
721+
result := nil;
722+
if not gzencode(@bytes[0], length(bytes), p, d, level, filename, comment) then exit;
723+
setlength(result, d);
724+
move(p^, result[0], d);
725+
freemem(p);
726+
end;
727+
689728
// -- GZIP decompress ---------------------
690729

691730
function gzdecode(data: pointer; size: dword; var output: pointer; var outputsize: dword): boolean;
@@ -722,6 +761,18 @@ function gzdecode(str: string): string;
722761
freemem(p);
723762
end;
724763

764+
function gzdecode(bytes: TBytes): TBytes;
765+
var
766+
p: pointer;
767+
d: dword;
768+
begin
769+
result := nil;
770+
if not gzdecode(@bytes[0], length(bytes), p, d) then exit;
771+
setlength(result, d);
772+
move(p^, result[0], d);
773+
freemem(p);
774+
end;
775+
725776
// -- decompress anything -----------------
726777

727778
function zdecompress(data: pointer; size: dword; var output: pointer; var outputsize: dword): boolean;
@@ -753,6 +804,18 @@ function zdecompress(str: string): string;
753804
freemem(p);
754805
end;
755806

807+
function zdecompress(bytes: TBytes): TBytes;
808+
var
809+
p: pointer;
810+
d: dword;
811+
begin
812+
result := nil;
813+
if not zdecompress(@bytes[0], length(bytes), p, d) then exit;
814+
setlength(result, d);
815+
move(p^, result[0], d);
816+
freemem(p);
817+
end;
818+
756819
// -- error translation -------------------
757820

758821
function zflatetranslatecode(code: integer): string;

0 commit comments

Comments
 (0)