code: def write_block_to_file(
      self, block: BlockAccessor, file: "pyarrow.NativeFile"
  ):
      stream = tarfile.open(fileobj=file, mode="w|")
      samples = _make_iterable(block)
      for sample in samples:
          if not isinstance(sample, dict):
              sample = sample.as_pydict()
          if self.encoder is not None:
              sample = _apply_list(
                  self.encoder, sample, default=_default_encoder
              )
          if "__key__" not in sample:
              sample["__key__"] = uuid.uuid4().hex
          key = sample["__key__"]
          for k, v in sample.items():
              if v is None or k.startswith("__"):
                  continue
              assert isinstance(v, bytes) or isinstance(v, str)
              if not isinstance(v, bytes):
                  v = v.encode("utf-8")
              ti = tarfile.TarInfo(f"{key}.{k}")
              ti.size = len(v)
              ti.mtime = time.time()
              ti.mode, ti.uname, ti.gname = 0o644, "data", "data"
              stream.addfile(ti, io.BytesIO(v))
      stream.close()
  
file_path: ray/python/ray/data/datasource/webdataset_datasink.py
imports: import io
  import tarfile
  import time
  import uuid
  from typing import Optional, Union
  import pyarrow
  from ray.data.block import BlockAccessor
  from ray.data.datasource.file_datasink import BlockBasedFileDatasink
  from ray.data.datasource.webdataset_datasource import _apply_list, _default_encoder, _make_iterable
label_desc: Use image node_id 2 for calling the _WebDatasetDatasink obj's underlying member method code with example usage: obj.write_block_to_file(block, file) without return types