code: def set_vtkwriter_mode(vtk_writer, use_binary=True):
      """Set any vtk writer to write as binary or ascii.
  
      Parameters
      ----------
      vtk_writer : vtkDataWriter, vtkPLYWriter, vtkSTLWriter, or _vtk.vtkXMLWriter
          The vtk writer instance to be configured.
      use_binary : bool, default: True
          If ``True``, the writer is set to write files in binary format. If
          ``False``, the writer is set to write files in ASCII format.
  
      Returns
      -------
      vtkDataWriter, vtkPLYWriter, vtkSTLWriter, or _vtk.vtkXMLWriter
          The configured vtk writer instance.
  
      """
      from vtkmodules.vtkIOGeometry import vtkSTLWriter
      from vtkmodules.vtkIOLegacy import vtkDataWriter
      from vtkmodules.vtkIOPLY import vtkPLYWriter
  
      if isinstance(
          vtk_writer, (vtkDataWriter, vtkPLYWriter, vtkSTLWriter)
      ):
          if use_binary:
              vtk_writer.SetFileTypeToBinary()
          else:
              vtk_writer.SetFileTypeToASCII()
      elif isinstance(vtk_writer, _vtk.vtkXMLWriter):
          if use_binary:
              vtk_writer.SetDataModeToBinary()
          else:
              vtk_writer.SetDataModeToAscii()
      return vtk_writer
  
imports: import os
  import pathlib
  import warnings
  import numpy
  import pyvista
  from pyvista.core import _vtk_core
  from pyvista.core.errors import PyVistaDeprecationWarning
  from .observers import Observer
label_desc: Use image node_id 4 for calling a global function with example usage: set_vtkwriter_mode(vtk_writer, use_binary) and returns: vtk_writer