mirror of
https://github.com/codedread/bitjs
synced 2025-10-03 09:39:16 +02:00
Better explanation for tee()
This commit is contained in:
parent
004cd8731a
commit
79c289afa1
1 changed files with 10 additions and 7 deletions
|
@ -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
|
||||
```
|
Loading…
Add table
Add a link
Reference in a new issue