unit dfilewriter;

//
//  Simple file writer. Works consistently with the dstreamfile.
//

{$MODE FPC}
{$MODESWITCH OUT}
{$MODESWITCH RESULT}

interface

uses
  dstreamfile;

function WriteFileContent(const FileName: AnsiString;
                          Content: Pointer;
                          ContentLen: SizeUInt): Boolean;

implementation

function WriteFileContent(const FileName: AnsiString;
                          Content: Pointer;
                          ContentLen: SizeUInt): Boolean;
var
  F: file of Byte;
  Written: SizeUInt;
begin
  Assign(F, FileName);
  {$I-}
  ReWrite(F);
  if IOResult <> 0 then
    Exit(False);
  BlockWrite(F, Content^, ContentLen, Written);
  if (IOResult <> 0) or (Written < ContentLen) then
    Exit(False);
  // Seems like untyped files do not have their own buffer and do not require
  // flush. Still wonder how to properly flush OS buffers...
  // Flush(F);
  Close(F);
  {$I+}
  Exit(IOResult = 0);
end;

end.
