function extract () {
  file_type=$(file -b ${1})
  file_type=${file_type%%,*}

  if [ -f ${1} ] ; then
    case ${file_type} in
      "bzip2 compressed data")
          tar xjvf "${1}"
          ;;
      "gzip compressed data")
          gunzip "${1}"
          ;;
      "XZ compressed data")
          xz -d "${1}"
          ;;
      "bzip2 compressed data")
          bzip2 -d "${1}"
          ;;
      "RAR archive data")
          unrar2dir "${1}"
          ;;
      "POSIX tar archive (GNU)")
          tar xf "${1}"
          ;;
      "Zip archive data")
          unzip "${1}"
          ;;
      "compress'd data 16 bits")
          uncompress "${1}"
          ;;
      "7-zip archive data")
          7z x "${1}"
          ;;
      "Zstandard compressed data"*)
	  zstd -d "${1}"
          ;;
      *)
          echo "'$1' cannot be extracted via extract()"
          ;;
    esac
  else
    echo "'${1}' not found."
    exit 1
  fi
}

