anchor.diff:    FQuoteChar := '"';
     FLineEnding := sLineBreak;
     FFilename:= '';
  -  FFilestream:= nil;
  +  FOwnedFileStream:= nil;
  +  FExtStream:= nil;
     FUTF8:= true;
     FCurrentRow := '';
   end;
   
   destructor TmCSVBuilder.Destroy;
   begin
  -  if Assigned(FFilestream) then
  +  if Assigned(FOwnedFileStream) then
       EndWrite;
     inherited Destroy;
   end;
   
   procedure TmCSVBuilder.StartWrite;
   begin
  -  if FFilename = '' then
  -    raise Exception.Create('Filename is empty');
  -
  -  if Assigned(FFilestream) then
  +  if Assigned(FOwnedFileStream) then
       EndWrite;
   
  -  FFileStream := TFileStream.Create(FFilename, fmCreate);
  -  if FUTF8 then
  -    AddUTF8BOMToFileStream(FFilestream);
  +  if Assigned(FExtStream) then
  +  begin
  +    if FUTF8 then
  +      AddUTF8BOMToStream(FExtStream);
  +  end
  +  else
  +  begin
  +    if (FFilename = '') then
  +      raise Exception.Create('Filename is empty');
  +    FOwnedFileStream := TFileStream.Create(FFilename, fmCreate);
  +    if FUTF8 then
  +      AddUTF8BOMToStream(FOwnedFileStream);
  +  end;
   end;
   
   procedure TmCSVBuilder.EndWrite;
   begin
  -  CheckFileStream;
     if FCurrentRow <> '' then
       AppendRow;
     FCurrentRow := '';
  -  FreeAndNil(FFilestream);
  +  FreeAndNil(FOwnedFileStream);
   end;
   
   procedure TmCSVBuilder.AppendCell(const aValue: String);
   begin
  -  CheckFileStream;
     if FCurrentRow <> '' then
       FCurrentRow := FCurrentRow + FDelimiter + aValue
     else
  
positive.code:     property LineEnding: String read FLineEnding write FLineEnding;
      property FileName: String read FFilename write FFilename;
      property UTF8: Boolean read FUTF8 write FUTF8;
    end;
  
  implementation
  
negative.code: procedure TmCSVBuilder.AppendRow;
  var
    s: RawByteString;
    fs : TStream;
  begin
    fs := CheckFileStream;
    FCurrentRow:= FCurrentRow + sLineBreak;
    if FUTF8 then
    begin
      s := UTF8Encode(FCurrentRow);
      fs.Write(s[1], Length(s));
    end
    else
      fs.Write(FCurrentRow[1], Length(FCurrentRow));
    FCurrentRow:= '';
  end;
  
  