我想將檔案壓縮到記憶體中的 Zip(我會將結果存盤在資料庫中,而不是在檔案系統中創建檔案)。
如何讀取壓縮 Zip 檔案的原始內容?我看不到任何讀取該內容的屬性,也看不到將該內容保存到 Stream 或任何其他記憶體結構中的任何方法。
function GetZip(UncompressedFile: TStream): TBytes;
var AZipFile: TZipFile;
begin
AZipFile := TZipFile.Create;
try
AZipFile.Add(UncompressedFile);
Result := AZipFile.Data; // ?? How to get the compressed file without saving it to the file system ??
finally
AZipfile.Free;
end;
end;
謝謝你。
uj5u.com熱心網友回復:
感謝 AmigoJack 和 Remy Lebeau 讓我知道我也可以使用 Zip 輸入流來獲得結果。
這很好用:
function Zip_AddFile(FileToAdd: TStream; Title: string): TBytes; overload;
begin
Result := Zip_AddFile([], FileToAdd, Title);
end;
function Zip_AddFile(Zip: TBytes; FileToAdd: TStream; Title: string): TBytes; overload;
var AZipFile: TZipFile;
ZipStream: TBytesStream;
begin
ZipStream := TBytesStream.Create(Zip);
AZipFile := TZipFile.Create;
try
AZipFile.Open(ZipStream, zmReadWrite);
AZipFile.Add(FileToAdd, Title);
AZipFile.Close;
Result := ZipStream.Bytes;
finally
AZipfile.Free;
ZipStream.Free;
end;
end;
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/536573.html
上一篇:使用查找表計算CRC-6GSM
