From 79c289afa1360e911da64da044bff9714756442e Mon Sep 17 00:00:00 2001 From: Jeff Schiller Date: Thu, 4 Jan 2024 22:47:41 +0900 Subject: [PATCH] Better explanation for tee() --- docs/bitjs.io.md | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/docs/bitjs.io.md b/docs/bitjs.io.md index 8708e89..bdbd957 100644 --- a/docs/bitjs.io.md +++ b/docs/bitjs.io.md @@ -69,13 +69,16 @@ the byte stream by using `someByteStream.push(nextBytesAsAnArrayBuffer)`. If you have a need to seek ahead to a different section of the stream of bytes, and want to later return to where you left off, you should use `tee()` method to make a copy of the ByteStream. This -will let you seek to the appropriate spot to grab some bytes. +will let you seek to the appropriate spot to grab some bytes using the teed stream, while you can +pick up where you left off with the original stream. ```javascript - const byteStream = new ByteStream(someArrayBuffer); - const strLen = byteStream.readNumber(4); // Bytes 0-3. - const strOffset = byteStream.readNumber(4); // Bytes 4-7. - // Grab bytes at that offset... - const description = byteStream.tee().skip(offset).readString(strLen); - const someOtherVal = byteStream.readNumber(4); // Bytes 8-11 + const origStream = new ByteStream(someArrayBuffer); + const strLen = origStream.readNumber(4); // Bytes 0-3. + const strOffset = origStream.readNumber(4); // Bytes 4-7. + + const teedStream = origStream.tee(); + const description = teedStream.skip(strOffset).readString(strLen); + + const someOtherVal = origStream.readNumber(4); // Bytes 8-11 ``` \ No newline at end of file