Skip to content

Commit 54ee7cd

Browse files
committed
update readme
1 parent f9cfa34 commit 54ee7cd

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ types.
2020
limits to mitigate resource exhaustion from malformed or malicious payloads.
2121
- **Telemetry Integration:** Emits standard `:telemetry` events for integration
2222
with monitoring tools.
23+
- **Streaming API:** Process large collections or continuous data streams with
24+
low memory overhead using `Msgpack.encode_stream/2` and
25+
`Msgpack.decode_stream/2`.
2326

2427
## Installation
2528

@@ -50,6 +53,27 @@ iex> Msgpack.decode!(<<0xC1>>)
5053
** (Msgpack.DecodeError) Unknown type prefix: 193. The byte `0xC1` is not a valid MessagePack type marker.
5154
```
5255

56+
### Streaming Large Collections
57+
58+
For datasets that may not fit in memory, you can use the streaming API, which
59+
processes one term at a time.
60+
61+
```elixir
62+
# Create a lazy stream of terms to be encoded.
63+
iex> terms = Stream.cycle([1, "elixir", true])
64+
65+
# The output is a lazy stream of encoded binaries.
66+
iex> encoded_stream = Msgpack.encode_stream(terms)
67+
68+
# The stream is only consumed when you enumerate it.
69+
iex> encoded_stream |> Stream.take(3) |> Enum.to_list()
70+
[
71+
{:ok, <<1>>},
72+
{:ok, <<166, 101, 108, 105, 120, 105, 114>>},
73+
{:ok, <<195>>}
74+
]
75+
```
76+
5377
## Full Documentation
5478

5579
For detailed information on all features, options, and functions, see the [full

0 commit comments

Comments
 (0)