怎样在D4中实现FTP功能?(50分)

  • 主题发起人 主题发起人 hhjjhhjj
  • 开始时间 开始时间
delphi自带有zlib压缩类
 
unit CompressProc;
interface
procedure Compress(var CompressedStream: TMemoryStream);
procedure UnCompress(var CompressedStream: TMemoryStream);

implementation
uses
zlib, Classes;

procedure Compress(var CompressedStream: TMemoryStream);
var
SourceStream: TCompressionStream;
DestStream: TMemoryStream;
Count: Integer;
Begin
Count := CompressedStream.Size;
DestStream := TMemoryStream.Create;
SourceStream:=TCompressionStream.Create(clMax, DestStream);
Try
CompressedStream.SaveToStream(SourceStream);
SourceStream.Free;
CompressedStream.Clear;
CompressedStream.WriteBuffer(Count, SizeOf(Count));
CompressedStream.CopyFrom(DestStream, 0);
finally
DestStream.Free;
end;
end;

procedure UnCompress(var CompressedStream: TMemoryStream);
var
SourceStream: TDecompressionStream;
DestStream: TMemoryStream;
Buffer: PChar;
Count: integer;
Begin
CompressedStream.Seek(0,soFromBeginning);
CompressedStream.ReadBuffer(Count, SizeOf(Count));
GetMem(Buffer, Count);
DestStream := TMemoryStream.Create;
SourceStream := TDecompressionStream.Create(CompressedStream);
Try
SourceStream.ReadBuffer(Buffer^, Count);
DestStream.WriteBuffer(Buffer^, Count);
DestStream.Position := 0; //复位流指针
CompressedStream.LoadFromStream(DestStream);
finally
FreeMem(Buffer);
DestStream.Free;
end;
end;

end.
 
多人接受答案了。
 
后退
顶部