合并(分割)流

合并(分割)流

/// <author>cxg 2020-3-15</author>
unit uStream;
 
interface
 
uses
  SysUtils, Classes;
 
type
  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: Int64;
  lnum: Integer;
  i: Integer;
begin
  ms.Position := 0;
  lnum := High(mss);
  ms.Write(LNum, SizeOf(Integer));  //有几个流
  for i := 0 to LNum - 1 do
  begin
    LSize := mss[i].Size;
    ms.Write(LSize, SizeOf(Int64));   // 流的大小
    ms.CopyFrom(mss[i], LSize);
  end;
end;
 
class procedure TynStream.SplitStream(ms: TStream; mss: TStreamArray);
var
  i: Integer;
  LSize: Int64;
  LNum: Integer;
begin
  ms.Position := 0;
  ms.Read(LNum, SizeOf(Integer)); //有几个流
  SetLength(mss, LNum);
  for i := 0 to LNum - 1 do
  begin
    ms.Read(LSize, SizeOf(Int64));   //流的大小
    mss[i] := TMemoryStream.Create;
    mss[i].CopyFrom(ms, LSize);
  end;
end;
 
end.

  

posted @ 2019-11-05 16:21  delphi中间件  阅读(382)  评论(0编辑  收藏  举报