@@ -404,6 +404,26 @@ public async Task ReadCanResumeInterruptedStreamAsync()
404404
405405 #region ReadByteLine() Tests
406406
407+ [ Fact ]
408+ // This unit test verifies that ReadByteLine can read a line which spans multiple chunks.
409+ // https://github.com/Http-Multipart-Data-Parser/Http-Multipart-Data-Parser/issues/40
410+ public void CanReadByteLineAccrossChunks ( )
411+ {
412+ // For this test to truly demonstrate that we can read a line which spans multiple chunks,
413+ // the newline needs to be at a position greater than the buffer size.
414+ var bufferSize = 5 ;
415+ var inputString = "0123456789ab\r \n cde" ;
416+
417+ var reader = new RebufferableBinaryReader ( TestUtil . StringToStreamNoBom ( inputString ) , Encoding . UTF8 , bufferSize ) ;
418+ var bytes = reader . ReadByteLine ( ) ;
419+ var expected = Encoding . UTF8 . GetBytes ( "0123456789ab" ) ;
420+
421+ foreach ( var pair in expected . Zip ( bytes , Tuple . Create ) )
422+ {
423+ Assert . Equal ( pair . Item1 , pair . Item2 ) ;
424+ }
425+ }
426+
407427 [ Fact ]
408428 public void CanReadByteLineOnMixedAsciiAndUTF8Text ( )
409429 {
@@ -421,6 +441,26 @@ public void CanReadByteLineOnMixedAsciiAndUTF8Text()
421441
422442 #region ReadByteLineAsync() Tests
423443
444+ [ Fact ]
445+ // This unit test verifies that ReadByteLine can read a line which spans multiple chunks.
446+ // https://github.com/Http-Multipart-Data-Parser/Http-Multipart-Data-Parser/issues/40
447+ public async Task CanReadByteLineAsyncAccrossChunks ( )
448+ {
449+ // For this test to truly demonstrate that we can read a line which spans multiple chunks,
450+ // the newline needs to be at a position greater than the buffer size.
451+ var bufferSize = 5 ;
452+ var inputString = "0123456789ab\r \n cde" ;
453+
454+ var reader = new RebufferableBinaryReader ( TestUtil . StringToStreamNoBom ( inputString ) , Encoding . UTF8 , bufferSize ) ;
455+ var bytes = await reader . ReadByteLineAsync ( TestContext . Current . CancellationToken ) ;
456+ var expected = Encoding . UTF8 . GetBytes ( "0123456789ab" ) ;
457+
458+ foreach ( var pair in expected . Zip ( bytes , Tuple . Create ) )
459+ {
460+ Assert . Equal ( pair . Item1 , pair . Item2 ) ;
461+ }
462+ }
463+
424464 [ Fact ]
425465 public async Task CanReadByteLineOnMixedAsciiAndUTF8TextAsync ( )
426466 {
0 commit comments