code: def open_file_in_dir(path: str) -> Tuple[io.FileIO, Optional[int]]:
      """Open a file and its directory.
  
      The file is opened in binary mode and created if it does not exist.
      Both file descriptors must be closed after use to prevent them from
      leaking.
  
      On Windows, the directory is not opened, as it is useless.
      """
      directory = os.path.dirname(path)
      if not os.path.isdir(directory):
          raise ValueError("No directory {}".format(directory))
  
      if not os.path.exists(path):
          file_fd = open(path, mode="x+b", buffering=0)
      else:
          file_fd = open(path, mode="r+b", buffering=0)
  
      if platform.system() == "Windows":
          # Opening a directory is not possible on Windows, but that is not
          # a problem since Windows does not need to fsync the directory in
          # order to persist metadata
          dir_fd = None
      else:
          dir_fd = os.open(directory, os.O_RDONLY)
  
      return file_fd, dir_fd
  
imports: import enum
  import io
  from logging import getLogger
  import os
  import platform
  from typing import Union, Tuple, Optional
  import cachetools
  import rwlock
  from .node import Node, FreelistNode
  from .const import ENDIAN, PAGE_REFERENCE_BYTES, OTHERS_BYTES, TreeConf, FRAME_TYPE_BYTES
label_desc: Use image node_id 1 for calling a global function with example usage: open_file_in_dir(path) and returns: file_fd,  dir_fd