You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It encodes `data` and returns a byte array as `Uint8Array`, throwing errors if `data` is, or includes, a non-serializable object such as a `function` or a `symbol`.
91
+
It encodes `data`into a single MessagePack-encoded object, and returns a byte array as `Uint8Array`, throwing errors if `data` is, or includes, a non-serializable object such as a `function` or a `symbol`.
If you'd like to convert the uint8array to a NodeJS `Buffer`, use `Buffer.from(arrayBuffer, offset, length)` in order not to copy the underlying `ArrayBuffer`, while `Buffer.from(uint8array)` copies it:
102
+
If you'd like to convert an `uint8array` to a NodeJS `Buffer`, use `Buffer.from(arrayBuffer, offset, length)` in order not to copy the underlying `ArrayBuffer`, while `Buffer.from(uint8array)` copies it:
It decodes `buffer`encoded in MessagePack, and returns a decoded object as`unknown`.
129
+
It decodes `buffer`that includes a MessagePack-encoded object, and returns the decoded object typed`unknown`.
130
130
131
131
`buffer` must be an array of bytes, which is typically `Uint8Array` or `ArrayBuffer`. `BufferSource` is defined as `ArrayBuffer | ArrayBufferView`.
132
132
133
+
In addition, `buffer` can include a single encoded object. If the `buffer` includes extra bytes after an object, it will throw `RangeError`. To decode `buffer` that includes multiple encoded objects, use `decodeMulti()` or `decodeMultiStream()` (recommended) instead.
134
+
133
135
for example:
134
136
135
137
```typescript
@@ -158,9 +160,9 @@ You can use `max${Type}Length` to limit the length of each type decoded.
It decodes `buffer`encoded in MessagePack, and returns decoded objects as a generator. That is, this is a synchronous variant for `decodeMultiStream()`.
163
+
It decodes `buffer`that includes multiple MessagePack-encoded objects, and returns decoded objects as a generator. That is, this is a synchronous variant for `decodeMultiStream()`.
162
164
163
-
This function is not recommended to decode a MessagePack binary via I/O stream including sockets because it's synchronous. Instead, `decodeMultiStream()` decodes it asynchronously, likely spending less time and memory.
165
+
This function is not recommended to decode a MessagePack binary via I/O stream including sockets because it's synchronous. Instead, `decodeMultiStream()` decodes it asynchronously, typically spending less time and memory.
164
166
165
167
for example:
166
168
@@ -176,7 +178,7 @@ for (const object of decodeMulti(encoded)) {
It decodes `stream`, where `ReadableStreamLike<T>` is defined as `ReadableStream<T> | AsyncIterable<T>`, in an async iterable of byte arrays, and returns decoded object as `unknown` type, wrapped in `Promise`. This function works asynchronously.
181
+
It decodes `stream`, where `ReadableStreamLike<T>` is defined as `ReadableStream<T> | AsyncIterable<T>`, in an async iterable of byte arrays, and returns decoded object as `unknown` type, wrapped in `Promise`. This function works asynchronously. This is an async variant for `decode()`.
180
182
181
183
`DecodeAsyncOptions` is the same as `DecodeOptions` for `decode()`.
It is alike to `decodeAsync()` and `decodeArrayStream()`, but the input `stream`consists of multiple MessagePack items.
219
+
It is alike to `decodeAsync()` and `decodeArrayStream()`, but the input `stream`must consist of multiple MessagePack-encoded items. This is an asynchronous variant for `decodeMulti()`.
221
220
222
-
In other words, it could decode an unlimited stream and emits an item one by one.
221
+
In other words, it could decode an unlimited stream and emits a decoded item one by one.
223
222
224
223
for example:
225
224
@@ -234,23 +233,7 @@ for await (const item of decodeStream(stream)) {
234
233
}
235
234
```
236
235
237
-
If you have a multi-values MessagePack binary, you can use `decodeMultiStream()`, but you need to convert it to a stream or an async generator like this:
0 commit comments