Skip to content

armgit / orca

Public Imported from GitHub
0

Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.

1.7 KB
Raw Blame
import { IMAGE_FILE_EXTENSIONS } from './image-file-extensions'

// Keep SVG out of binary extensions because editors open it as source text.
const TEXT_IMAGE_EXTENSIONS = new Set(['.svg'])

const NON_IMAGE_BINARY_EXTENSIONS = [
  // Archives
  '.7z',
  '.bz2',
  '.gz',
  '.jar',
  '.rar',
  '.tar',
  '.tgz',
  '.war',
  '.xz',
  '.zip',
  '.zst',
  // Audio and video
  '.aac',
  '.avi',
  '.flac',
  '.m4a',
  '.mkv',
  '.mov',
  '.mp3',
  '.mp4',
  '.ogg',
  '.wav',
  '.webm',
  // Documents
  '.doc',
  '.docx',
  '.pdf',
  '.ppt',
  '.pptx',
  '.xls',
  '.xlsx',
  // Fonts
  '.eot',
  '.otf',
  '.ttc',
  '.ttf',
  '.woff',
  '.woff2',
  // Compiled artifacts and datastores
  '.a',
  '.bin',
  '.class',
  '.dll',
  '.dylib',
  '.exe',
  '.idx',
  '.lockb',
  '.node',
  '.o',
  '.pack',
  '.pyc',
  '.pyd',
  '.so',
  '.sqlite',
  '.sqlite3',
  '.wasm'
]

export const BINARY_FILE_EXTENSIONS: readonly string[] = Object.freeze([
  ...IMAGE_FILE_EXTENSIONS.filter((extension) => !TEXT_IMAGE_EXTENSIONS.has(extension)),
  ...NON_IMAGE_BINARY_EXTENSIONS
])

const BINARY_FILE_EXTENSION_SET = new Set(BINARY_FILE_EXTENSIONS)

/** Guess by extension only without bytes; use isBinaryBuffer for content-based detection. */
export function hasBinaryFileExtension(filePath: string | undefined): boolean {
  if (filePath === undefined) {
    return false
  }
  const lowerPath = filePath.toLowerCase()
  const dotIndex = lowerPath.lastIndexOf('.')
  const separatorIndex = Math.max(lowerPath.lastIndexOf('/'), lowerPath.lastIndexOf('\\'))
  // A leading dot is a dotfile (.gitignore), not an extension.
  if (dotIndex <= separatorIndex + 1) {
    return false
  }
  return BINARY_FILE_EXTENSION_SET.has(lowerPath.slice(dotIndex))
}