From 028779b9ec948c1730c7eec5fb18a4061aaad797 Mon Sep 17 00:00:00 2001 From: meixg Date: Sat, 12 Feb 2022 22:32:51 +0800 Subject: [PATCH] doc: fix bug in stream doc, unshift example --- doc/api/stream.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/api/stream.md b/doc/api/stream.md index 3a46d2fe7e9bb8..ca64bed920f38c 100644 --- a/doc/api/stream.md +++ b/doc/api/stream.md @@ -1586,7 +1586,7 @@ function parseHeader(stream, callback) { let chunk; while (null !== (chunk = stream.read())) { const str = decoder.write(chunk); - if (str.match(/\n\n/)) { + if (str.includes('\n\n')) { // Found the header boundary. const split = str.split(/\n\n/); header += split.shift(); @@ -1599,10 +1599,10 @@ function parseHeader(stream, callback) { stream.unshift(buf); // Now the body of the message can be read from the stream. callback(null, header, stream); - } else { - // Still reading the header. - header += str; + return; } + // Still reading the header. + header += str; } } }