Skip to content

Commit 79c289a

Browse files
committed
Better explanation for tee()
1 parent 004cd87 commit 79c289a

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

docs/bitjs.io.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,16 @@ the byte stream by using `someByteStream.push(nextBytesAsAnArrayBuffer)`.
6969

7070
If you have a need to seek ahead to a different section of the stream of bytes, and want to later
7171
return to where you left off, you should use `tee()` method to make a copy of the ByteStream. This
72-
will let you seek to the appropriate spot to grab some bytes.
72+
will let you seek to the appropriate spot to grab some bytes using the teed stream, while you can
73+
pick up where you left off with the original stream.
7374

7475
```javascript
75-
const byteStream = new ByteStream(someArrayBuffer);
76-
const strLen = byteStream.readNumber(4); // Bytes 0-3.
77-
const strOffset = byteStream.readNumber(4); // Bytes 4-7.
78-
// Grab bytes at that offset...
79-
const description = byteStream.tee().skip(offset).readString(strLen);
80-
const someOtherVal = byteStream.readNumber(4); // Bytes 8-11
76+
const origStream = new ByteStream(someArrayBuffer);
77+
const strLen = origStream.readNumber(4); // Bytes 0-3.
78+
const strOffset = origStream.readNumber(4); // Bytes 4-7.
79+
80+
const teedStream = origStream.tee();
81+
const description = teedStream.skip(strOffset).readString(strLen);
82+
83+
const someOtherVal = origStream.readNumber(4); // Bytes 8-11
8184
```

0 commit comments

Comments
 (0)