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;
本文来自博客园,作者:{咏南中间件},转载请注明原文链接:https://www.cnblogs.com/hnxxcxg/p/9633007.html