// deprecated since dstream supported buffered read/write itself
{$MODE OBJFPC}
{$MODESWITCH result}
{$MODESWITCH autoderef}
unit dbuffered;

interface

uses
  dstream;

type
TBuffered = object
private
  FStream: PStream;
  FBuffer: array of Byte;
  FPos: LongInt;
  FEnd: PByte;
public
  procedure Init(Stream: PStream; BufSize: LongInt); inline;
  procedure Done; inline;
  function Refresh(Required: LongInt = 0): Boolean;
  function GetPtr(Required: LongInt = 0): PByte; inline;
  function Skip(Bytes: LongInt): PByte; inline;
end;

implementation

procedure TBuffered.Init(Stream: PStream; BufSize: LongInt);
begin
  FStream := Stream;
  SetLength(FBuffer, BufSize);
end;

procedure TBuffered.Done;
begin
end;

function TBuffered.Refresh(Required: LongInt = 0): Boolean;
begin
  Result := True;
end;

function TBuffered.GetPtr(Required: LongInt = 0): PByte;
begin
  Result := @FBuffer[FPos];
end;

function TBuffered.Skip(Bytes: LongInt): PByte;
begin
  Inc(FPos, Bytes);
end;

end.
