   cluster but we never truncate in the middle of a binary
   codepoint. For this reason, truncation is not exact.
   """
-  @spec truncate(IO.chardata, non_neg_integer) :: IO.chardata
+  @spec truncate(IO.chardata(), non_neg_integer) :: IO.chardata()
   def truncate(chardata, :infinity) when is_binary(chardata) or is_list(chardata) do
     chardata
   end
+
   def truncate(chardata, n) when n >= 0 do
     {chardata, n} = truncate_n(chardata, n)
     if n >= 0, do: chardata, else: [chardata, " (truncated)"]

    end
  end

  defp truncate_n(int, n) when int in 0..127,                      do: {int, n - 1}
  defp truncate_n(int, n) when int in 127..0x07FF,                 do: {int, n - 2}
  defp truncate_n(int, n) when int in 0x800..0xFFFF,               do: {int, n - 3}
  defp truncate_n(int, n) when int >= 0x10000 and is_integer(int), do: {int, n - 4}

  defp truncate_n(list, n) when is_list(list) do


  defp truncate_n(binary, n) when is_binary(binary) do
    remaining = n - byte_size(binary)

    if remaining < 0 do
      # There is a chance we are cutting at the wrong
      # place so we need to fix the binary.
