msgpackr 1.6.1 → 1.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -1,12 +1,23 @@
1
- export { Unpackr, Decoder, unpack, decode, addExtension, FLOAT32_OPTIONS, clearSource, roundFloat32, isNativeAccelerationEnabled } from './unpack'
2
- import { Options } from './unpack'
3
- export { Packr, Encoder, pack, encode } from './pack'
4
- import { Transform, Readable } from 'stream'
5
-
6
- export as namespace msgpackr;
7
- export class UnpackrStream extends Transform {
8
- constructor(options?: Options | { highWaterMark: number, emitClose: boolean, allowHalfOpen: boolean })
9
- }
10
- export class PackrStream extends Transform {
11
- constructor(options?: Options | { highWaterMark: number, emitClose: boolean, allowHalfOpen: boolean })
12
- }
1
+ export {
2
+ Unpackr,
3
+ Decoder,
4
+ unpack,
5
+ unpackMultiple,
6
+ decode,
7
+ addExtension,
8
+ FLOAT32_OPTIONS,
9
+ clearSource,
10
+ roundFloat32,
11
+ isNativeAccelerationEnabled,
12
+ } from './unpack'
13
+ import { Options } from './unpack'
14
+ export { Packr, Encoder, pack, encode } from './pack'
15
+ import { Transform, Readable } from 'stream'
16
+
17
+ export as namespace msgpackr;
18
+ export class UnpackrStream extends Transform {
19
+ constructor(options?: Options | { highWaterMark: number, emitClose: boolean, allowHalfOpen: boolean })
20
+ }
21
+ export class PackrStream extends Transform {
22
+ constructor(options?: Options | { highWaterMark: number, emitClose: boolean, allowHalfOpen: boolean })
23
+ }
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
- export { Packr, Encoder, addExtension, pack, encode, NEVER, ALWAYS, DECIMAL_ROUND, DECIMAL_FIT, REUSE_BUFFER_MODE } from './pack.js'
2
- export { Unpackr, Decoder, C1, unpack, unpackMultiple, decode, FLOAT32_OPTIONS, clearSource, roundFloat32, isNativeAccelerationEnabled } from './unpack.js'
3
- export { decodeIter, encodeIter } from './iterators.js'
4
- export const useRecords = false
5
- export const mapsAsObjects = true
1
+ export { Packr, Encoder, addExtension, pack, encode, NEVER, ALWAYS, DECIMAL_ROUND, DECIMAL_FIT, REUSE_BUFFER_MODE } from './pack.js'
2
+ export { Unpackr, Decoder, C1, unpack, unpackMultiple, decode, FLOAT32_OPTIONS, clearSource, roundFloat32, isNativeAccelerationEnabled } from './unpack.js'
3
+ export { decodeIter, encodeIter } from './iterators.js'
4
+ export const useRecords = false
5
+ export const mapsAsObjects = true
package/iterators.js CHANGED
@@ -1,87 +1,87 @@
1
- import { Packr } from './pack.js'
2
- import { Unpackr } from './unpack.js'
3
-
4
- /**
5
- * Given an Iterable first argument, returns an Iterable where each value is packed as a Buffer
6
- * If the argument is only Async Iterable, the return value will be an Async Iterable.
7
- * @param {Iterable|Iterator|AsyncIterable|AsyncIterator} objectIterator - iterable source, like a Readable object stream, an array, Set, or custom object
8
- * @param {options} [options] - msgpackr pack options
9
- * @returns {IterableIterator|Promise.<AsyncIterableIterator>}
10
- */
11
- export function packIter (objectIterator, options = {}) {
12
- if (!objectIterator || typeof objectIterator !== 'object') {
13
- throw new Error('first argument must be an Iterable, Async Iterable, or a Promise for an Async Iterable')
14
- } else if (typeof objectIterator[Symbol.iterator] === 'function') {
15
- return packIterSync(objectIterator, options)
16
- } else if (typeof objectIterator.then === 'function' || typeof objectIterator[Symbol.asyncIterator] === 'function') {
17
- return packIterAsync(objectIterator, options)
18
- } else {
19
- throw new Error('first argument must be an Iterable, Async Iterable, Iterator, Async Iterator, or a Promise')
20
- }
21
- }
22
-
23
- function * packIterSync (objectIterator, options) {
24
- const packr = new Packr(options)
25
- for (const value of objectIterator) {
26
- yield packr.pack(value)
27
- }
28
- }
29
-
30
- async function * packIterAsync (objectIterator, options) {
31
- const packr = new Packr(options)
32
- for await (const value of objectIterator) {
33
- yield packr.pack(value)
34
- }
35
- }
36
-
37
- /**
38
- * Given an Iterable/Iterator input which yields buffers, returns an IterableIterator which yields sync decoded objects
39
- * Or, given an Async Iterable/Iterator which yields promises resolving in buffers, returns an AsyncIterableIterator.
40
- * @param {Iterable|Iterator|AsyncIterable|AsyncIterableIterator} bufferIterator
41
- * @param {object} [options] - unpackr options
42
- * @returns {IterableIterator|Promise.<AsyncIterableIterator}
43
- */
44
- export function unpackIter (bufferIterator, options = {}) {
45
- if (!bufferIterator || typeof bufferIterator !== 'object') {
46
- throw new Error('first argument must be an Iterable, Async Iterable, Iterator, Async Iterator, or a promise')
47
- }
48
-
49
- const unpackr = new Unpackr(options)
50
- let incomplete
51
- const parser = (chunk) => {
52
- let yields
53
- // if there's incomplete data from previous chunk, concatinate and try again
54
- if (incomplete) {
55
- chunk = Buffer.concat([incomplete, chunk])
56
- incomplete = undefined
57
- }
58
-
59
- try {
60
- yields = unpackr.unpackMultiple(chunk)
61
- } catch (err) {
62
- if (err.incomplete) {
63
- incomplete = chunk.slice(err.lastPosition)
64
- yields = err.values
65
- } else {
66
- throw err
67
- }
68
- }
69
- return yields
70
- }
71
-
72
- if (typeof bufferIterator[Symbol.iterator] === 'function') {
73
- return (function * iter () {
74
- for (const value of bufferIterator) {
75
- yield * parser(value)
76
- }
77
- })()
78
- } else if (typeof bufferIterator[Symbol.asyncIterator] === 'function') {
79
- return (async function * iter () {
80
- for await (const value of bufferIterator) {
81
- yield * parser(value)
82
- }
83
- })()
84
- }
85
- }
86
- export const decodeIter = unpackIter
1
+ import { Packr } from './pack.js'
2
+ import { Unpackr } from './unpack.js'
3
+
4
+ /**
5
+ * Given an Iterable first argument, returns an Iterable where each value is packed as a Buffer
6
+ * If the argument is only Async Iterable, the return value will be an Async Iterable.
7
+ * @param {Iterable|Iterator|AsyncIterable|AsyncIterator} objectIterator - iterable source, like a Readable object stream, an array, Set, or custom object
8
+ * @param {options} [options] - msgpackr pack options
9
+ * @returns {IterableIterator|Promise.<AsyncIterableIterator>}
10
+ */
11
+ export function packIter (objectIterator, options = {}) {
12
+ if (!objectIterator || typeof objectIterator !== 'object') {
13
+ throw new Error('first argument must be an Iterable, Async Iterable, or a Promise for an Async Iterable')
14
+ } else if (typeof objectIterator[Symbol.iterator] === 'function') {
15
+ return packIterSync(objectIterator, options)
16
+ } else if (typeof objectIterator.then === 'function' || typeof objectIterator[Symbol.asyncIterator] === 'function') {
17
+ return packIterAsync(objectIterator, options)
18
+ } else {
19
+ throw new Error('first argument must be an Iterable, Async Iterable, Iterator, Async Iterator, or a Promise')
20
+ }
21
+ }
22
+
23
+ function * packIterSync (objectIterator, options) {
24
+ const packr = new Packr(options)
25
+ for (const value of objectIterator) {
26
+ yield packr.pack(value)
27
+ }
28
+ }
29
+
30
+ async function * packIterAsync (objectIterator, options) {
31
+ const packr = new Packr(options)
32
+ for await (const value of objectIterator) {
33
+ yield packr.pack(value)
34
+ }
35
+ }
36
+
37
+ /**
38
+ * Given an Iterable/Iterator input which yields buffers, returns an IterableIterator which yields sync decoded objects
39
+ * Or, given an Async Iterable/Iterator which yields promises resolving in buffers, returns an AsyncIterableIterator.
40
+ * @param {Iterable|Iterator|AsyncIterable|AsyncIterableIterator} bufferIterator
41
+ * @param {object} [options] - unpackr options
42
+ * @returns {IterableIterator|Promise.<AsyncIterableIterator}
43
+ */
44
+ export function unpackIter (bufferIterator, options = {}) {
45
+ if (!bufferIterator || typeof bufferIterator !== 'object') {
46
+ throw new Error('first argument must be an Iterable, Async Iterable, Iterator, Async Iterator, or a promise')
47
+ }
48
+
49
+ const unpackr = new Unpackr(options)
50
+ let incomplete
51
+ const parser = (chunk) => {
52
+ let yields
53
+ // if there's incomplete data from previous chunk, concatinate and try again
54
+ if (incomplete) {
55
+ chunk = Buffer.concat([incomplete, chunk])
56
+ incomplete = undefined
57
+ }
58
+
59
+ try {
60
+ yields = unpackr.unpackMultiple(chunk)
61
+ } catch (err) {
62
+ if (err.incomplete) {
63
+ incomplete = chunk.slice(err.lastPosition)
64
+ yields = err.values
65
+ } else {
66
+ throw err
67
+ }
68
+ }
69
+ return yields
70
+ }
71
+
72
+ if (typeof bufferIterator[Symbol.iterator] === 'function') {
73
+ return (function * iter () {
74
+ for (const value of bufferIterator) {
75
+ yield * parser(value)
76
+ }
77
+ })()
78
+ } else if (typeof bufferIterator[Symbol.asyncIterator] === 'function') {
79
+ return (async function * iter () {
80
+ for await (const value of bufferIterator) {
81
+ yield * parser(value)
82
+ }
83
+ })()
84
+ }
85
+ }
86
+ export const decodeIter = unpackIter
87
87
  export const encodeIter = packIter
package/node-index.js CHANGED
@@ -1,24 +1,24 @@
1
- export { Packr, Encoder, addExtension, pack, encode, NEVER, ALWAYS, DECIMAL_ROUND, DECIMAL_FIT } from './pack.js'
2
- export { Unpackr, Decoder, C1, unpack, unpackMultiple, decode, FLOAT32_OPTIONS, clearSource, roundFloat32, isNativeAccelerationEnabled } from './unpack.js'
3
- export { PackrStream, UnpackrStream, PackrStream as EncoderStream, UnpackrStream as DecoderStream } from './stream.js'
4
- export { decodeIter, encodeIter } from './iterators.js'
5
- export const useRecords = false
6
- export const mapsAsObjects = true
7
- import { setExtractor } from './unpack.js'
8
- import { createRequire } from 'module'
9
-
10
- const nativeAccelerationDisabled = process.env.MSGPACKR_NATIVE_ACCELERATION_DISABLED !== undefined && process.env.MSGPACKR_NATIVE_ACCELERATION_DISABLED.toLowerCase() === 'true';
11
-
12
- if (!nativeAccelerationDisabled) {
13
- let extractor
14
- try {
15
- if (typeof require == 'function')
16
- extractor = require('msgpackr-extract')
17
- else
18
- extractor = createRequire(import.meta.url)('msgpackr-extract')
19
- if (extractor)
20
- setExtractor(extractor.extractStrings)
21
- } catch (error) {
22
- // native module is optional
23
- }
1
+ export { Packr, Encoder, addExtension, pack, encode, NEVER, ALWAYS, DECIMAL_ROUND, DECIMAL_FIT } from './pack.js'
2
+ export { Unpackr, Decoder, C1, unpack, unpackMultiple, decode, FLOAT32_OPTIONS, clearSource, roundFloat32, isNativeAccelerationEnabled } from './unpack.js'
3
+ export { PackrStream, UnpackrStream, PackrStream as EncoderStream, UnpackrStream as DecoderStream } from './stream.js'
4
+ export { decodeIter, encodeIter } from './iterators.js'
5
+ export const useRecords = false
6
+ export const mapsAsObjects = true
7
+ import { setExtractor } from './unpack.js'
8
+ import { createRequire } from 'module'
9
+
10
+ const nativeAccelerationDisabled = process.env.MSGPACKR_NATIVE_ACCELERATION_DISABLED !== undefined && process.env.MSGPACKR_NATIVE_ACCELERATION_DISABLED.toLowerCase() === 'true';
11
+
12
+ if (!nativeAccelerationDisabled) {
13
+ let extractor
14
+ try {
15
+ if (typeof require == 'function')
16
+ extractor = require('msgpackr-extract')
17
+ else
18
+ extractor = createRequire(import.meta.url)('msgpackr-extract')
19
+ if (extractor)
20
+ setExtractor(extractor.extractStrings)
21
+ } catch (error) {
22
+ // native module is optional
23
+ }
24
24
  }
package/pack.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { Unpackr } from './unpack'
2
- export { addExtension, FLOAT32_OPTIONS } from './unpack'
3
- export class Packr extends Unpackr {
4
- pack(value: any): Buffer
5
- encode(value: any): Buffer
6
- }
7
- export class Encoder extends Packr {}
8
- export function pack(value: any): Buffer
9
- export function encode(value: any): Buffer
1
+ import { Unpackr } from './unpack'
2
+ export { addExtension, FLOAT32_OPTIONS } from './unpack'
3
+ export class Packr extends Unpackr {
4
+ pack(value: any): Buffer
5
+ encode(value: any): Buffer
6
+ }
7
+ export class Encoder extends Packr {}
8
+ export function pack(value: any): Buffer
9
+ export function encode(value: any): Buffer