msgpack传文件

msgpack传文件

procedure TForm1.Button1Click(Sender: TObject);
var
ms, ms2: TMemoryStream;
pack: TSimpleMsgPack;
begin
ms := TMemoryStream.Create;
ms.LoadFromFile(ExtractFilePath(Application.ExeName) + '1.exe');//流加载文件
pack := TSimpleMsgPack.Create;
pack.ForcePathObject('a').LoadBinaryFromStream(ms);//msgpack加载
ms.Free;

pack.EncodeToStream(); //msgpack转为流后,网络传输流

pack.DecodeFromStream();//客户端收到流后,转化为msgpack

ms2 := TMemoryStream.Create;
pack.ForcePathObject('a').SaveBinaryToStream(ms2);
pack.Free;
ms2.SaveToFile(ExtractFilePath(Application.ExeName) + '2.exe');//流保存为本地文件
ms2.Free;
end;

 

posted @ 2018-09-12 09:52  delphi中间件  阅读(586)  评论(0编辑  收藏  举报