function normalizeMode(mode) {
  // Note: BrowserFS will use -1 for "unknown"
  // I need to make it non-negative for these bitshifts to work.
  let type = mode > 0 ? mode >> 12 : 0
  // If it isn't valid, assume it as a "regular file"
  // 0100 = directory
  // 1000 = regular file
  // 1010 = symlink
  // 1110 = gitlink
  if (
    type !== 0b0100 &&
    type !== 0b1000 &&
    type !== 0b1010 &&
    type !== 0b1110
  ) {
    type = 0b1000
  }
  let permissions = mode & 0o777
  // Is the file executable? then 755. Else 644.
  if (permissions & 0b001001001) {
    permissions = 0o755
  } else {
    permissions = 0o644
  }
  // If it's not a regular file, scrub all permissions
  if (type !== 0b1000) permissions = 0
  return (type << 12) + permissions
}
From https://github.com/git/git/blob/master/Documentation/technical/index-format.txt

32-bit mode, split into (high to low bits)

 4-bit object type
   valid values in binary are 1000 (regular file), 1010 (symbolic link)
   and 1110 (gitlink)

 3-bit unused

 9-bit unix permission. Only 0755 and 0644 are valid for regular files.
 Symbolic links and gitlinks have value 0 in this field.