'Write string array `arr` with given `codec`'

def write_char(self, arr, codec='ascii'):

    if ((arr.size == 0) or np.all((arr == ''))):
        shape = ((0,) * np.max([arr.ndim, 2]))
        self.write_header(shape, mxCHAR_CLASS)
        self.write_smalldata_element(arr, miUTF8, 0)
        return
    arr = arr_to_chars(arr)
    shape = arr.shape
    self.write_header(shape, mxCHAR_CLASS)
    if ((arr.dtype.kind == 'U') and arr.size):
        n_chars = np.product(shape)
        st_arr = np.ndarray(shape=(), dtype=arr_dtype_number(arr, n_chars), buffer=arr.T.copy())
        st = st_arr.item().encode(codec)
        arr = np.ndarray(shape=(len(st),), dtype='S1', buffer=st)
    self.write_element(arr, mdtype=miUTF8)
