function isBinary(buffer) {
  // in canonical git, this check happens in builtins/merge-file.c
  // but I think it's DRYer to do it here.
  // The value picked is explained here: https://github.com/git/git/blob/ab15ad1a3b4b04a29415aef8c9afa2f64fc194a2/xdiff-interface.h#L12
  const MAX_XDIFF_SIZE = 1024 * 1024 * 1023
  if (buffer.length > MAX_XDIFF_SIZE) return true
  // check for null characters in the first 8000 bytes
  return buffer.slice(0, 8000).some(value => value === 0)
}
Determine whether a file is binary (and therefore not worth trying to merge automatically)

@param {Uint8Array} buffer

If it looks incredibly simple / naive to you, compare it with the original:

// xdiff-interface.c

#define FIRST_FEW_BYTES 8000
int buffer_is_binary(const char *ptr, unsigned long size)
{
 if (FIRST_FEW_BYTES < size)
  size = FIRST_FEW_BYTES;
 return !!memchr(ptr, 0, size);
}

Yup, that's how git does it. We could try to be smarter