code: def open_by_file_pattern(
      filename: Union[str, Path], mode: str = "r", **kwargs: Any
  ) -> Any:
      """Can read/write to files on gcs/local with or without gzipping. If file
      is stored on gcs, streams with blobfile. Otherwise use vanilla python open. If
      filename endswith gz, then zip/unzip contents on the fly (note that gcs paths and
      gzip are compatible)"""
      open_fn = partial(bf.BlobFile, **kwargs)
  
      if isinstance(filename, Path):
          filename = filename.as_posix()
  
      try:
          if filename.endswith(".gz"):
              return gzip_open(filename, openhook=open_fn, mode=mode)
          elif filename.endswith(".lz4"):
              return lz4_open(filename, openhook=open_fn, mode=mode)
          elif filename.endswith(".zst"):
              return zstd_open(filename, openhook=open_fn, mode=mode)
          else:
              scheme = urllib.parse.urlparse(filename).scheme
              if (not os.path.exists(filename)) and (
                  scheme == "" or scheme == "file"
              ):
                  return open_fn(
                      os.path.join(
                          os.path.dirname(os.path.abspath(__file__)),
                          "registry",
                          "data",
                          filename,
                      ),
                      mode=mode,
                  )
              else:
                  return open_fn(filename, mode=mode)
      except Exception as e:
          raise RuntimeError(f"Failed to open: {filename}") from e
  
imports: import csv
  import dataclasses
  import gzip
  import itertools
  import json
  import logging
  import os
  import urllib
  from collections.abc import Iterator
  from functools import partial
  from pathlib import Path
  from typing import Any, List, Optional, Sequence, Text, Union
  import blobfile
  import lz4.frame
  import pydantic
  import pyzstd
label_desc: Use image node_id 4 for calling a global function with example usage: open_by_file_pattern(filename, mode) and returns: gzip_open, lz4_open, zstd_open, open_fn, open_fn