Ignore:
Timestamp:
May 7, 2012, 10:32:41 AM (13 years ago)
Author:
chronos
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • CoolStreaming/UStreamHelper.pas

    r307 r360  
    66
    77uses
    8   Classes, DateUtils, syncobjs;
     8  Classes, DateUtils, syncobjs, SysUtils;
    99
    1010type
     
    4949    procedure ReadStream(AStream: TStream; Count: Integer);
    5050    procedure ReadStreamPart(AStream: TStream; Count: Integer);
     51    function EqualTo(Source: TStream): Boolean;
    5152    function Sum: Byte;
    5253    procedure FillByte(Data: Byte; Count: Integer);
     
    159160end;
    160161
     162function TStreamHelper.EqualTo(Source: TStream): Boolean;
     163const
     164  BlockSize = 4096;
     165var
     166  Buffer1: array[0..BlockSize - 1] of Byte;
     167  Buffer2: array[0..BlockSize - 1] of Byte;
     168  BufferLength: Integer;
     169  OldPos1, OldPos2: Integer;
     170begin
     171  OldPos1 := Source.Position;
     172  Source.Position := 0;
     173  OldPos2 := Position;
     174  Position := 0;
     175  Result := True;
     176  if Source.Size = Size then begin
     177    while Source.Position < Source.Size do begin
     178      BufferLength := Source.Read(Buffer1, BlockSize);
     179      Read(Buffer2, BlockSize);
     180      if not CompareMem(@Buffer1, @Buffer2, BufferLength) then begin
     181        Result := False;
     182        Break;
     183      end;
     184    end;
     185  end else Result := False;
     186  Source.Position := OldPos1;
     187  Position := OldPos2;
     188end;
     189
    161190procedure TStreamHelper.WriteStreamPart(AStream: TStream; Count: Integer);
    162191var
Note: See TracChangeset for help on using the changeset viewer.