@@ -721,19 +721,20 @@ export async function init(options?: {
721721 const status = engine . stream_get_status ( streamId ) ;
722722 if ( status !== 1 /* complete */ && status !== 3 /* end_early */ ) return null ;
723723 const bufPtr = engine . stream_get_buffer_ptr ( streamId ) >>> 0 ;
724- const bufLen = engine . stream_get_buffer_len ( streamId ) ;
725- if ( bufLen === 0 ) return null ;
726- // Copy stream buffer with SIMD padding for doc_parse
727- const padPtr = engine . alloc ( bufLen + 64 ) >>> 0 ;
724+ // Use value_len (not buffer_len) — in JSONL mode buffer may contain next value's bytes
725+ const valueLen = engine . stream_get_value_len ( streamId ) ;
726+ if ( valueLen === 0 ) return null ;
727+ // Copy with SIMD padding for doc_parse
728+ const padPtr = engine . alloc ( valueLen + 64 ) >>> 0 ;
728729 if ( padPtr === 0 ) return null ;
729- new Uint8Array ( engine . memory . buffer , padPtr , bufLen ) . set (
730- new Uint8Array ( engine . memory . buffer , bufPtr , bufLen ) ,
730+ new Uint8Array ( engine . memory . buffer , padPtr , valueLen ) . set (
731+ new Uint8Array ( engine . memory . buffer , bufPtr , valueLen ) ,
731732 ) ;
732- new Uint8Array ( engine . memory . buffer , padPtr + bufLen , 64 ) . fill ( 0x20 ) ;
733+ new Uint8Array ( engine . memory . buffer , padPtr + valueLen , 64 ) . fill ( 0x20 ) ;
733734 const docId = formatCode === 2
734- ? engine . doc_parse_fmt ( padPtr , bufLen , 2 )
735- : engine . doc_parse ( padPtr , bufLen ) ;
736- engine . dealloc ( padPtr , bufLen + 64 ) ;
735+ ? engine . doc_parse_fmt ( padPtr , valueLen , 2 )
736+ : engine . doc_parse ( padPtr , valueLen ) ;
737+ engine . dealloc ( padPtr , valueLen + 64 ) ;
737738 if ( docId < 0 ) return null ;
738739 // Export tape → JS ArrayBuffer, then free slot
739740 const size = engine . doc_export_tape_size ( docId ) ;
0 commit comments