Fix `IO::Encoder#write` when operating on long strings (#16797)