Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
reececomo authored Aug 5, 2024
1 parent c682fca commit 4ce5612
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,14 @@ bytes.byteLength
// 17
```

> [!CAUTION]
> By default `BufferFormat.encode(…)` optimizes performance and memory by
> encoding data to a shared buffer, and returning a `Uint8Array` pointer
> to the encoded bytes.
> [!WARNING]
> **Safe mode:** `encode(…)` optimizes performance and memory by encoding bytes
> into a shared buffer, and returning a `Uint8Array` pointer. Subsequent calls
> are destructive and unsuitable for asyncronous workflows (e.g. Promises, Web Workers).
>
> Subsequent calls to `encode(…)` are destructive, so this would be
> unsuitable for asyncronous usage (e.g. Promises, Web Workers).
> `encode(…)` returns an unsafe `Uint8Array` view of the shared encoding buffer.
>
> Call `encode({ … }, true)` to copy bytes to a safe buffer on encode, or set
> `setTinybufConfig({ safe: true })` (but be mindful of memory fragmentation).
> Enable safe encode to automatically copy bytes to a safe buffer instead:
> - `myFormat.encode({ /*…*/ }, true )`
> - `setTinybufConfig({ safe: true })`
#### Decode

Expand Down

0 comments on commit 4ce5612

Please sign in to comment.