mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-22 23:49:29 +02:00
* Add additional parameters to Unzip calls. Fix issue 39530
This commit is contained in:
parent
bb91dadb00
commit
42361be239
@ -585,9 +585,12 @@ Type
|
||||
Class Procedure Unzip(const AZipFileName : RawByteString);
|
||||
// Unzip a single file.
|
||||
Class Procedure Unzip(const AZipFileName : RawByteString;aExtractFileName : RawByteString);
|
||||
Class Procedure UnZip(const AZipFileName, aExtractFileName: RawByteString; aOutputFileName : string);
|
||||
// Unzip several files
|
||||
Class Procedure Unzip(const AZipFileName : RawByteString; aFileList : Array of RawByteString);
|
||||
Class Procedure Unzip(const AZipFileName : RawByteString; aFileList : TStrings);
|
||||
Class Procedure Unzip(const AZipFileName : RawByteString; aFileList : Array of RawByteString; aOutputDir : RawByteString; aFlat : Boolean = false);
|
||||
Class Procedure Unzip(const AZipFileName : RawByteString; aFileList : TStrings; aOutputDir : RawByteString; aFlat : Boolean = false);
|
||||
Procedure Clear;
|
||||
Procedure Examine;
|
||||
Procedure Terminate;
|
||||
@ -3020,6 +3023,62 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
Type
|
||||
|
||||
{ TCustomExtractor }
|
||||
|
||||
TCustomExtractor = Class(TObject)
|
||||
Private
|
||||
FStream : TStream;
|
||||
FunZipper : TUnzipper;
|
||||
procedure DoCreateStream(Sender: TObject; var AStream: TStream; AItem: TFullZipFileEntry);
|
||||
Public
|
||||
Constructor Create(aUnZipper : TUnzipper);
|
||||
Destructor Destroy; override;
|
||||
Procedure UnZip(const AZipFileName, aExtractFileName: RawByteString; aOutputFileName: string);
|
||||
end;
|
||||
|
||||
{ TCustomExtractor }
|
||||
|
||||
procedure TCustomExtractor.DoCreateStream(Sender: TObject; var AStream: TStream; AItem: TFullZipFileEntry);
|
||||
begin
|
||||
aStream:=FStream;
|
||||
FStream:=Nil;
|
||||
end;
|
||||
|
||||
constructor TCustomExtractor.Create(aUnZipper: TUnzipper);
|
||||
begin
|
||||
FStream:=Nil;
|
||||
FUnzipper:=aUnzipper;
|
||||
end;
|
||||
|
||||
destructor TCustomExtractor.Destroy;
|
||||
begin
|
||||
FreeAndNil(FUnZipper);
|
||||
FreeAndNil(FStream);
|
||||
Inherited;
|
||||
end;
|
||||
|
||||
procedure TCustomExtractor.UnZip(const AZipFileName, aExtractFileName: RawByteString; aOutputFileName: string);
|
||||
begin
|
||||
FStream:=TFileStream.Create(aOutputFileName,fmCreate);
|
||||
FUnZipper.OnCreateStream:=@DoCreateStream;
|
||||
FUnzipper.UnzipFile(aZipFileName,aExtractFileName);
|
||||
end;
|
||||
|
||||
class procedure TUnZipper.UnZip(const AZipFileName, aExtractFileName: RawByteString; aOutputFileName: string);
|
||||
|
||||
|
||||
|
||||
begin
|
||||
With TCustomExtractor.Create(Self.Create) do
|
||||
try
|
||||
Unzip(aZipFileName,aExtractFileName,aOutputFileName);
|
||||
Finally
|
||||
Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
class procedure TUnZipper.Unzip(const AZipFileName: RawByteString; aFileList: array of RawByteString);
|
||||
begin
|
||||
With Self.Create do
|
||||
@ -3040,6 +3099,31 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
class procedure TUnZipper.Unzip(const AZipFileName: RawByteString; aFileList: array of RawByteString; aOutputDir: RawByteString;
|
||||
aFlat: Boolean);
|
||||
begin
|
||||
With Self.Create do
|
||||
try
|
||||
Flat:=aFlat;
|
||||
OutputPath:=aOutputDir;
|
||||
UnZipFiles(aZipFileName,aFileList);
|
||||
finally
|
||||
Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
class procedure TUnZipper.Unzip(const AZipFileName: RawByteString; aFileList: TStrings; aOutputDir: RawByteString; aFlat: Boolean);
|
||||
begin
|
||||
With Self.Create do
|
||||
try
|
||||
Flat:=aFlat;
|
||||
OutputPath:=aOutputDir;
|
||||
UnZipFiles(aZipFileName,aFileList);
|
||||
finally
|
||||
Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TUnZipper.DoEndOfFile;
|
||||
|
||||
Var
|
||||
|
BIN
packages/paszlib/tests/test.zip
Normal file
BIN
packages/paszlib/tests/test.zip
Normal file
Binary file not shown.
57
packages/paszlib/tests/testsingle.lpi
Normal file
57
packages/paszlib/tests/testsingle.lpi
Normal file
@ -0,0 +1,57 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<CONFIG>
|
||||
<ProjectOptions>
|
||||
<Version Value="12"/>
|
||||
<General>
|
||||
<Flags>
|
||||
<MainUnitHasCreateFormStatements Value="False"/>
|
||||
<MainUnitHasTitleStatement Value="False"/>
|
||||
<MainUnitHasScaledStatement Value="False"/>
|
||||
</Flags>
|
||||
<SessionStorage Value="InProjectDir"/>
|
||||
<Title Value="testsingle"/>
|
||||
<UseAppBundle Value="False"/>
|
||||
<ResourceType Value="res"/>
|
||||
</General>
|
||||
<BuildModes>
|
||||
<Item Name="Default" Default="True"/>
|
||||
</BuildModes>
|
||||
<PublishOptions>
|
||||
<Version Value="2"/>
|
||||
<UseFileFilters Value="True"/>
|
||||
</PublishOptions>
|
||||
<RunParams>
|
||||
<FormatVersion Value="2"/>
|
||||
</RunParams>
|
||||
<Units>
|
||||
<Unit>
|
||||
<Filename Value="testsingle.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
</Unit>
|
||||
</Units>
|
||||
</ProjectOptions>
|
||||
<CompilerOptions>
|
||||
<Version Value="11"/>
|
||||
<Target>
|
||||
<Filename Value="testsingle"/>
|
||||
</Target>
|
||||
<SearchPaths>
|
||||
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||
<OtherUnitFiles Value="../src"/>
|
||||
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
|
||||
</SearchPaths>
|
||||
</CompilerOptions>
|
||||
<Debugging>
|
||||
<Exceptions>
|
||||
<Item>
|
||||
<Name Value="EAbort"/>
|
||||
</Item>
|
||||
<Item>
|
||||
<Name Value="ECodetoolError"/>
|
||||
</Item>
|
||||
<Item>
|
||||
<Name Value="EFOpenError"/>
|
||||
</Item>
|
||||
</Exceptions>
|
||||
</Debugging>
|
||||
</CONFIG>
|
19
packages/paszlib/tests/testsingle.pas
Normal file
19
packages/paszlib/tests/testsingle.pas
Normal file
@ -0,0 +1,19 @@
|
||||
program testsingle;
|
||||
|
||||
uses sysutils, zipper;
|
||||
|
||||
Var
|
||||
FN : String;
|
||||
|
||||
begin
|
||||
FN:=GetTempFileName;
|
||||
TUnzipper.Unzip('test.zip','files/file1.txt',FN);
|
||||
if not FileExists(FN) then
|
||||
Writeln('Error: no file named ',FN)
|
||||
else
|
||||
begin
|
||||
// DeleteFile(FN);
|
||||
Writeln('OK for ',fn);
|
||||
end;
|
||||
end.
|
||||
|
Loading…
Reference in New Issue
Block a user