Dies hatte ich auch schon veruscht, und hab das Crate und Assigned rausgenohmen und vor DecompressStream nur Create gemacht und auch in DecompressStrema nur Create, funkt alles nichts. Es hängt halt nur an diese stelle.
EDIT:Okay....ehm ja...Es funkt jetzt, hab ne vermutung worans lag, ich hab zum schluss den Stream von der TStreamLisT im DecompressStream-Code freigegeben, ich glaub daran lags. Hab nochmal getestet funk jetzt.
Danke Sir Rufo für die Hilfe. Manchmal liegt der Fehler so na und doch so fern xD
Hier der fertige Code fals es mal jemand brauch xD
Delphi-Quellcode:
type
TZLibEntpackedStream = class(TMemoryStream) //Da TMemoryStream von TObject bereits abstammt
private
FFileName : TFileName;
public
property FileName : TFileName read FFileName write FFileName;
end;
TStreamList = class(TObjectList)
protected
function GetItem(Index: Integer): TZLibEntpackedStream;
procedure SetItem(Index: Integer; AStream: TZLibEntpackedStream);
public
function Add(AStream: TZLibEntpackedStream): Integer;
function Remove(AStream: TZLibEntpackedStream): Integer;
function IndexOf(AStream: TZLibEntpackedStream): Integer;
function First: TZLibEntpackedStream;
function Last: TZLibEntpackedStream;
procedure Insert(Index: Integer; AStream: TZLibEntpackedStream);
property Items[Index: Integer]: TZLibEntpackedStream read GetItem write SetItem; default;
end;
TStreamZlibMultiple = class(TJvZlibMultiple)
public
procedure DecompressIntoStream(Stream: TStream; var StreamList : TStreamList);
end;
implementation
function TStreamList.GetItem(Index: Integer): TZLibEntpackedStream;
begin
Result := TZLibEntpackedStream(inherited GetItem(Index));
end;
procedure TStreamList.SetItem(Index: Integer; AStream: TZLibEntpackedStream);
begin
inherited Items[Index] := AStream;
end;
function TStreamList.Add(AStream: TZLibEntpackedStream) : Integer;
begin
Result := inherited Add(AStream);
end;
function TStreamList.Remove(AStream: TZLibEntpackedStream): Integer;
begin
Result := inherited Remove(AStream);
end;
function TStreamList.IndexOf(AStream: TZLibEntpackedStream): Integer;
begin
Result := inherited IndexOf(AStream);
end;
function TStreamList.First: TZLibEntpackedStream;
begin
Result := TZLibEntpackedStream(inherited First);
end;
function TStreamList.Last: TZLibEntpackedStream;
begin
Result := TZLibEntpackedStream(inherited Last);
end;
procedure TStreamList.Insert(Index: Integer; AStream: TZLibEntpackedStream);
begin
inherited Insert(Index,AStream);
end;
procedure TStreamZlibMultiple.DecompressIntoStream(Stream: TStream; var StreamList : TStreamList);
var
MemoryStream: TZLibEntpackedStream;
ZStream: TJclZLibDecompressStream;
CStream: TMemoryStream;
B, LastPos: Byte;
AnsiS: AnsiString;
S: string;
Count, FileSize, I: Integer;
Buffer: array [0..1023] of Byte;
TotalByteCount: Longword;
FileStreamSize, StreamSize: Int64;
begin
StreamList := TStreamList.Create;
StreamSize := Stream.Size; // cache, to not FileSeek on every iteration
while Stream.Position < StreamSize do
begin
//Read and force the directory //Fällt weg weil ich das net brauch muss aber Count gelesen werden
Stream.Read(B, SizeOf(B));
S := '';
//Read filename
Stream.Read(B, SizeOf(B));
if B > 0 then
begin
AnsiS := AnsiString(S);
LastPos := Length(AnsiS);
SetLength(AnsiS, LastPos + B);
Stream.Read(AnsiS[LastPos + 1], B);
S := string(AnsiS);
end;
Stream.Read(FileSize, SizeOf(FileSize));
Stream.Read(I, SizeOf(I));
CStream := TMemoryStream.Create;
try
CStream.CopyFrom(Stream, I);
CStream.Position := 0;
//Decompress the file
MemoryStream := TZLibEntpackedStream.Create;
StreamList.Add(MemoryStream);
MemoryStream.FFileName := S;
ZStream := TJclZLibDecompressStream.Create(CStream);
try
TotalByteCount := 0;
{ (RB) ZStream has an OnProgress event, thus copyfrom can be used }
FileStreamSize := 0;
repeat
Count := ZStream.Read(Buffer, SizeOf(Buffer));
if Assigned(MemoryStream) then
begin
Inc(FileStreamSize, MemoryStream.Write(Buffer, Count));
DoProgress(FileStreamSize, FileSize);
end;
Inc(TotalByteCount, Count);
until Count = 0;
if Assigned(OnDecompressedFile) then
OnDecompressedFile(Self, S, TotalByteCount);
finally
ZStream.Free;
end;
finally
CStream.Free;
end;
end;
end;