@@ -179,6 +179,10 @@ pub fn from_reader<R: std::io::Read + ?Sized>(
179179 loop {
180180 let mut total_read = 0usize;
181181
182+ // An inner loop is necessary as it is possible that the input buffer
183+ // may not be completely decoded on the first `decode_to_str()` call
184+ // which would happen in cases where the output buffer is filled to
185+ // capacity.
182186 loop {
183187 let (result, read, written, ..) = decoder.decode_to_str(
184188 &slice[total_read..],
@@ -252,6 +256,10 @@ pub async fn to_writer<'a, W: tokio::io::AsyncWriteExt + Unpin + ?Sized>(
252256 let is_empty = chunk.is_empty();
253257 let mut total_read = 0usize;
254258
259+ // An inner loop is necessary as it is possible that the input buffer
260+ // may not be completely encoded on the first `encode_from_utf8()` call
261+ // which would happen in cases where the output buffer is filled to
262+ // capacity.
255263 loop {
256264 let (result, read, written, ..) =
257265 encoder.encode_from_utf8(&chunk[total_read..], &mut buf[total_written..], is_empty);