@eyhn/msgpack-stream
Version:
MessagePack for ECMA-262/JavaScript/TypeScript
42 lines • 2.58 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import { Decoder } from "./Decoder.mjs";
import { ensureAsyncIterable } from "./utils/stream.mjs";
import { defaultDecodeOptions } from "./decode.mjs";
/**
* @throws {@link RangeError} if the buffer is incomplete, including the case where the buffer is empty.
* @throws {@link DecodeError} if the buffer contains invalid data.
*/
export function decodeAsync(streamLike, options = defaultDecodeOptions) {
return __awaiter(this, void 0, void 0, function* () {
const stream = ensureAsyncIterable(streamLike);
const decoder = new Decoder(options.extensionCodec, options.context, options.maxStrLength, options.maxBinLength, options.maxArrayLength, options.maxMapLength, options.maxExtLength);
return decoder.decodeAsync(stream);
});
}
/**
* @throws {@link RangeError} if the buffer is incomplete, including the case where the buffer is empty.
* @throws {@link DecodeError} if the buffer contains invalid data.
*/
export function decodeArrayStream(streamLike, options = defaultDecodeOptions) {
const stream = ensureAsyncIterable(streamLike);
const decoder = new Decoder(options.extensionCodec, options.context, options.maxStrLength, options.maxBinLength, options.maxArrayLength, options.maxMapLength, options.maxExtLength);
return decoder.decodeArrayStream(stream);
}
/**
* @throws {@link RangeError} if the buffer is incomplete, including the case where the buffer is empty.
* @throws {@link DecodeError} if the buffer contains invalid data.
*/
export function decodeMultiStream(streamLike, options = defaultDecodeOptions) {
const stream = ensureAsyncIterable(streamLike);
const decoder = new Decoder(options.extensionCodec, options.context, options.maxStrLength, options.maxBinLength, options.maxArrayLength, options.maxMapLength, options.maxExtLength);
return decoder.decodeStream(stream);
}
//# sourceMappingURL=decodeAsync.mjs.map