:: MVP ::
|
|
:: RSS ::
|
|
|
Как узнать минимальную версию RAR, необходимую для распаковки архива?
function GetRarVersion(FileName: string): Double;
var
f: file of Byte;
Ver: Byte;
begin
AssignFile(f, FileName);
Reset(f);
Seek(f, $2C);
Read(f, Ver);
CloseFile(f);
Result := Ver / 10;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(FloatToStr(GetRarVersion('c:\test.rar')));
end;
|
Как сжать файл с помощью ZLib?
uses
ZLib;
procedure CompressStream(Source: TStream; Dest: TStream = nil; aLevel: TCompressionLevel = clFastest);
var
DataSize: Integer;
MemoryStream: TMemoryStream;
begin
MemoryStream := TMemoryStream.Create;
try
DataSize := Source.Size;
MemoryStream.Write(DataSize, SizeOf(DataSize));
with TCompressionStream.Create(aLevel, MemoryStream) do
try
CopyFrom(Source, 0);
finally
Free;
end;
if Dest = nil then
begin
Source.Size := 0;
Dest := Source;
end;
Dest.CopyFrom(MemoryStream, 0);
finally
MemoryStream.Free;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
sIn, sOut: TFileStream;
begin
sIn := TFileStream.Create('c:\test.txt', fmOpenRead);
try
sOut := TFileStream.Create('c:\test.lzip', fmCreate or fmOpenWrite);
try
CompressStream(sIn, sOut, clMax);
finally
sOut.Free;
end;
finally
sIn.Free;
end;
end;
|
Как разжать файл с помощью ZLib?
uses
ZLib;
procedure DecompressStream(Source: TStream; Dest: TStream = nil);
var
DataSize: Integer;
MemoryStream: TMemoryStream;
D: TDecompressionStream;
begin
MemoryStream := TMemoryStream.Create;
try
Source.Read(DataSize, SizeOf(DataSize));
D := TDecompressionStream.Create(Source);
with D do
try
MemoryStream.CopyFrom(D, DataSize);
finally
D.Free;
end;
if Dest = nil then
begin
Source.Size := 0;
Dest := Source;
end;
Dest.CopyFrom(MemoryStream, 0);
finally
MemoryStream.Free;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
sIn, sOut: TFileStream;
begin
sIn := TFileStream.Create('c:\test.lzip', fmOpenRead);
try
sOut := TFileStream.Create('c:\test.txt', fmCreate or fmOpenWrite);
try
DecompressStream(sIn, sOut);
finally
sOut.Free;
end;
finally
sIn.Free;
end;
end;
|
При использовании материала - ссылка на сайт обязательна
|
|