I just realised that I have a problem

I have my LoadPNGFromFile() routine, and I wanted to make a LoadPNGFromStream() version...

The problem is that in the loading code below requires a pointer to a PNG file, and the length!!

Code:
function LoadPNGFromFile(FileName: String; Buffer: TImageBuffer32): Boolean;
var
  PNGFile  : TMemoryStream;
  PNGData  : Pointer;
  PNGWidth : Integer;
  PNGHeight: Integer;
  PNGAddr  : PRGBA;
  BufferRow: PRGBAArray;
  x,y      : Integer;
begin
  Result := False;

  if not FileExists(FileName) then Exit;

  PNGFile := TMemoryStream.Create;
  try
    PNGFile.LoadFromFile(FileName);
    Result := LoadPNG(PNGFile.Memory,PNGFile.Size,PNGData,PNGWidth,PNGHeight);
    if not Result then Exit;

    Buffer.SetSize(PNGWidth,PNGHeight);

    PNGAddr := PNGData;
    // copy bitmap pixels to buffer pixels
    for y := 0 to PNGHeight - 1 do
    begin
      BufferRow := Buffer.ScanLine[y];
      for x := 0 to PNGWidth - 1 do
      begin
        BufferRow^[x].r := PNGAddr^.r;
        BufferRow^[x].g := PNGAddr^.g;
        BufferRow^[x].b := PNGAddr^.b;
        BufferRow^[x].a := PNGAddr^.a;
        Inc(PNGAddr);
      end;
    end;
  finally
    PNGFile.Free;
  end;
end;
the loading code in the BeRo file uses the DataSize parameter as an indicator of when the PNG file has been read in, I would like to be able to change this so that the code knows when to stop without the user passing in the size.

Any ideas?

cheers,
Paul