unit uStream; interface uses System.SysUtils, System.Classes; type TStreamSize = packed record size: int64; end; TStreamNum = packed record num: Integer; end; TStreamArray = array of TStream; type TynStream = class private { Private declarations } public { Public declarations } class procedure MergeStream(ms: TStream; mss: TStreamArray); class procedure SplitStream(ms: TStream; mss: TStreamArray); end; var ynStream: TynStream; implementation class procedure TynStream.MergeStream(ms: TStream; mss: TStreamArray); var LSize: TStreamSize; LNum: TStreamNum; i: Integer; begin ms.Position := 0; LNum.num := High(mss); ms.Write(LNum, SizeOf(Integer)); //有几个流 for i := 0 to LNum.num - 1 do begin LSize.size := mss[i].Size; ms.Write(LSize, SizeOf(Int64)); // 流的大小 ms.CopyFrom(mss[i], LSize.size); end; end; class procedure TynStream.SplitStream(ms: TStream; mss: TStreamArray); var i: Integer; LSize: TStreamSize; LNum: TStreamNum; begin ms.Position := 0; ms.Read(LNum, SizeOf(Integer)); //有几个流 SetLength(mss, LNum.num); for i := 0 to LNum.num - 1 do begin ms.Read(LSize, SizeOf(Int64)); //流的大小 mss[i] := TMemoryStream.Create; mss[i].CopyFrom(ms, LSize.size); end; end; end.
原文地址:https://www.cnblogs.com/hnxxcxg/p/11799255.html
时间: 2024-10-09 07:17:11