@@ -23,10 +23,17 @@ defmodule Msgpack.StreamDecoder do
2323 alias Msgpack.Decoder
2424 alias Msgpack.Decoder.Internal
2525
26- @ typedoc "A stream that yields decoded Elixir terms. "
27- @ type t :: Stream . t ( )
26+ @ typedoc "" "
27+ A stream that yields decoded Elixir terms or a final error tuple.
2828
29- @ typedoc "Options passed to the decoder."
29+ The stream will produce any t:term/0 that can be decoded from the input.
30+
31+ If the input enumerable finishes while a term is only partially decoded, the
32+ last element in the stream will be {:error, :unexpected_eof}.
33+ """
34+ @ type t :: Stream . t ( term ( ) | { :error , :unexpected_eof } )
35+
36+ @ typedoc "Options passed to the decoder for each object."
3037 @ type opts_t :: keyword ( )
3138
3239 @ doc """
@@ -36,7 +43,7 @@ defmodule Msgpack.StreamDecoder do
3643 ## Parameters
3744
3845 * `enumerable`: An `Enumerable` that yields chunks of a MessagePack binary
39- stream (e.g., `File.stream/3` or a list of binaries).
46+ stream (e.g., `f: File.stream/3` or a list of binaries).
4047 * `opts`: A keyword list of options passed to the underlying decoder.
4148
4249 ## Return Value
@@ -90,7 +97,11 @@ defmodule Msgpack.StreamDecoder do
9097 end
9198
9299 @ doc false
93- @ spec transform_chunk ( binary ( ) | :eof , { binary ( ) , opts_t ( ) } ) :: { list ( ) , { binary ( ) , opts_t ( ) | nil } }
100+ @ spec transform_chunk (
101+ binary ( ) | :eof ,
102+ { binary ( ) , opts_t ( ) }
103+ ) ::
104+ { list ( term ( ) | { :error , :unexpected_eof } ) , { binary ( ) , opts_t ( ) | nil } }
94105 defp transform_chunk ( :eof , { << >> , _opts } ) do
95106 { [ ] , { << >> , nil } }
96107 end
@@ -105,7 +116,7 @@ defmodule Msgpack.StreamDecoder do
105116 end
106117
107118 @ doc false
108- @ spec do_transform ( binary ( ) , opts_t ( ) , list ( ) ) :: { list ( ) , binary ( ) }
119+ @ spec do_transform ( binary ( ) , opts_t ( ) , list ( term ( ) ) ) :: { list ( term ( ) ) , binary ( ) }
109120 defp do_transform ( << >> , _opts , acc ) do
110121 { Enum . reverse ( acc ) , << >> }
111122 end
0 commit comments