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/LICENSE +21 -21
- package/README.md +335 -335
- package/SECURITY.md +11 -11
- package/benchmark.md +67 -67
- package/dist/index.js +2022 -2003
- package/dist/index.js.map +1 -0
- package/dist/index.min.js +77 -77
- package/dist/index.min.js.map +1 -0
- package/dist/node.cjs +2137 -2118
- package/dist/node.cjs.map +1 -0
- package/dist/test.js +708 -674
- package/dist/test.js.map +1 -0
- package/index.d.ts +23 -12
- package/index.js +5 -5
- package/iterators.js +86 -86
- package/node-index.js +23 -23
- package/pack.d.ts +9 -9
- package/pack.js +935 -933
- package/package.json +83 -83
- package/rollup.config.js +45 -45
- package/stream.js +57 -57
- package/unpack.d.ts +52 -50
- package/unpack.js +1070 -1053
package/package.json
CHANGED
|
@@ -1,83 +1,83 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "msgpackr",
|
|
3
|
-
"author": "Kris Zyp",
|
|
4
|
-
"version": "1.6.
|
|
5
|
-
"description": "Ultra-fast MessagePack implementation with extensions for records and structured cloning",
|
|
6
|
-
"license": "MIT",
|
|
7
|
-
"types": "./index.d.ts",
|
|
8
|
-
"main": "./dist/node.cjs",
|
|
9
|
-
"module": "./index.js",
|
|
10
|
-
"keywords": [
|
|
11
|
-
"MessagePack",
|
|
12
|
-
"msgpack",
|
|
13
|
-
"performance",
|
|
14
|
-
"structured",
|
|
15
|
-
"clone"
|
|
16
|
-
],
|
|
17
|
-
"repository": {
|
|
18
|
-
"type": "git",
|
|
19
|
-
"url": "http://github.com/kriszyp/msgpackr"
|
|
20
|
-
},
|
|
21
|
-
"scripts": {
|
|
22
|
-
"benchmark": "node ./tests/benchmark.cjs",
|
|
23
|
-
"build": "rollup -c",
|
|
24
|
-
"dry-run": "npm publish --dry-run",
|
|
25
|
-
"prepare": "npm run build",
|
|
26
|
-
"test": "mocha tests/test**.*js -u tdd --experimental-json-modules"
|
|
27
|
-
},
|
|
28
|
-
"type": "module",
|
|
29
|
-
"exports": {
|
|
30
|
-
".": {
|
|
31
|
-
"node": {
|
|
32
|
-
"require": "./dist/node.cjs",
|
|
33
|
-
"import": "./node-index.js"
|
|
34
|
-
},
|
|
35
|
-
"bun": {
|
|
36
|
-
"require": "./dist/node.cjs",
|
|
37
|
-
"import": "./node-index.js"
|
|
38
|
-
},
|
|
39
|
-
"default": "./index.js"
|
|
40
|
-
},
|
|
41
|
-
"./pack": {
|
|
42
|
-
"node": {
|
|
43
|
-
"import": "./index.js",
|
|
44
|
-
"require": "./dist/node.cjs"
|
|
45
|
-
},
|
|
46
|
-
"bun": {
|
|
47
|
-
"import": "./index.js",
|
|
48
|
-
"require": "./dist/node.cjs"
|
|
49
|
-
},
|
|
50
|
-
"default": "./pack.js"
|
|
51
|
-
},
|
|
52
|
-
"./unpack": {
|
|
53
|
-
"node": {
|
|
54
|
-
"import": "./index.js",
|
|
55
|
-
"require": "./dist/node.cjs"
|
|
56
|
-
},
|
|
57
|
-
"bun": {
|
|
58
|
-
"import": "./index.js",
|
|
59
|
-
"require": "./dist/node.cjs"
|
|
60
|
-
},
|
|
61
|
-
"default": "./unpack.js"
|
|
62
|
-
}
|
|
63
|
-
},
|
|
64
|
-
"files": [
|
|
65
|
-
"/dist",
|
|
66
|
-
"*.md",
|
|
67
|
-
"/*.js",
|
|
68
|
-
"/*.ts"
|
|
69
|
-
],
|
|
70
|
-
"optionalDependencies": {
|
|
71
|
-
"msgpackr-extract": "^2.0.2"
|
|
72
|
-
},
|
|
73
|
-
"devDependencies": {
|
|
74
|
-
"@rollup/plugin-json": "^4.1.0",
|
|
75
|
-
"@types/node": "latest",
|
|
76
|
-
"async": "^3",
|
|
77
|
-
"chai": "^4.3.4",
|
|
78
|
-
"esm": "^3.2.25",
|
|
79
|
-
"mocha": "^8.1.3",
|
|
80
|
-
"rollup": "^1.20.3",
|
|
81
|
-
"rollup-plugin-babel-minify": "^9.0.0"
|
|
82
|
-
}
|
|
83
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "msgpackr",
|
|
3
|
+
"author": "Kris Zyp",
|
|
4
|
+
"version": "1.6.3",
|
|
5
|
+
"description": "Ultra-fast MessagePack implementation with extensions for records and structured cloning",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"types": "./index.d.ts",
|
|
8
|
+
"main": "./dist/node.cjs",
|
|
9
|
+
"module": "./index.js",
|
|
10
|
+
"keywords": [
|
|
11
|
+
"MessagePack",
|
|
12
|
+
"msgpack",
|
|
13
|
+
"performance",
|
|
14
|
+
"structured",
|
|
15
|
+
"clone"
|
|
16
|
+
],
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "http://github.com/kriszyp/msgpackr"
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"benchmark": "node ./tests/benchmark.cjs",
|
|
23
|
+
"build": "rollup -c",
|
|
24
|
+
"dry-run": "npm publish --dry-run",
|
|
25
|
+
"prepare": "npm run build",
|
|
26
|
+
"test": "mocha tests/test**.*js -u tdd --experimental-json-modules"
|
|
27
|
+
},
|
|
28
|
+
"type": "module",
|
|
29
|
+
"exports": {
|
|
30
|
+
".": {
|
|
31
|
+
"node": {
|
|
32
|
+
"require": "./dist/node.cjs",
|
|
33
|
+
"import": "./node-index.js"
|
|
34
|
+
},
|
|
35
|
+
"bun": {
|
|
36
|
+
"require": "./dist/node.cjs",
|
|
37
|
+
"import": "./node-index.js"
|
|
38
|
+
},
|
|
39
|
+
"default": "./index.js"
|
|
40
|
+
},
|
|
41
|
+
"./pack": {
|
|
42
|
+
"node": {
|
|
43
|
+
"import": "./index.js",
|
|
44
|
+
"require": "./dist/node.cjs"
|
|
45
|
+
},
|
|
46
|
+
"bun": {
|
|
47
|
+
"import": "./index.js",
|
|
48
|
+
"require": "./dist/node.cjs"
|
|
49
|
+
},
|
|
50
|
+
"default": "./pack.js"
|
|
51
|
+
},
|
|
52
|
+
"./unpack": {
|
|
53
|
+
"node": {
|
|
54
|
+
"import": "./index.js",
|
|
55
|
+
"require": "./dist/node.cjs"
|
|
56
|
+
},
|
|
57
|
+
"bun": {
|
|
58
|
+
"import": "./index.js",
|
|
59
|
+
"require": "./dist/node.cjs"
|
|
60
|
+
},
|
|
61
|
+
"default": "./unpack.js"
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
"files": [
|
|
65
|
+
"/dist",
|
|
66
|
+
"*.md",
|
|
67
|
+
"/*.js",
|
|
68
|
+
"/*.ts"
|
|
69
|
+
],
|
|
70
|
+
"optionalDependencies": {
|
|
71
|
+
"msgpackr-extract": "^2.0.2"
|
|
72
|
+
},
|
|
73
|
+
"devDependencies": {
|
|
74
|
+
"@rollup/plugin-json": "^4.1.0",
|
|
75
|
+
"@types/node": "latest",
|
|
76
|
+
"async": "^3",
|
|
77
|
+
"chai": "^4.3.4",
|
|
78
|
+
"esm": "^3.2.25",
|
|
79
|
+
"mocha": "^8.1.3",
|
|
80
|
+
"rollup": "^1.20.3",
|
|
81
|
+
"rollup-plugin-babel-minify": "^9.0.0"
|
|
82
|
+
}
|
|
83
|
+
}
|
package/rollup.config.js
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
import minify from "rollup-plugin-babel-minify";
|
|
2
|
-
import json from "@rollup/plugin-json";
|
|
3
|
-
|
|
4
|
-
export default [
|
|
5
|
-
{
|
|
6
|
-
input: "node-index.js",
|
|
7
|
-
output: [
|
|
8
|
-
{
|
|
9
|
-
file: "dist/node.cjs",
|
|
10
|
-
format: "cjs"
|
|
11
|
-
}
|
|
12
|
-
]
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
input: "index.js",
|
|
16
|
-
output: {
|
|
17
|
-
file: "dist/index.js",
|
|
18
|
-
format: "umd",
|
|
19
|
-
name: "msgpackr"
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
input: "index.js",
|
|
24
|
-
plugins: [minify({
|
|
25
|
-
})],
|
|
26
|
-
output: {
|
|
27
|
-
file: "dist/index.min.js",
|
|
28
|
-
format: "umd",
|
|
29
|
-
name: "msgpackr"
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
input: "tests/test.js",
|
|
34
|
-
plugins: [json()],
|
|
35
|
-
external: ['chai', '../index.js'],
|
|
36
|
-
output: {
|
|
37
|
-
file: "dist/test.js",
|
|
38
|
-
format: "iife",
|
|
39
|
-
globals: {
|
|
40
|
-
chai: 'chai',
|
|
41
|
-
'./index.js': 'msgpackr',
|
|
42
|
-
},
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
];
|
|
1
|
+
import minify from "rollup-plugin-babel-minify";
|
|
2
|
+
import json from "@rollup/plugin-json";
|
|
3
|
+
|
|
4
|
+
export default [
|
|
5
|
+
{
|
|
6
|
+
input: "node-index.js",
|
|
7
|
+
output: [
|
|
8
|
+
{
|
|
9
|
+
file: "dist/node.cjs",
|
|
10
|
+
format: "cjs"
|
|
11
|
+
}
|
|
12
|
+
]
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
input: "index.js",
|
|
16
|
+
output: {
|
|
17
|
+
file: "dist/index.js",
|
|
18
|
+
format: "umd",
|
|
19
|
+
name: "msgpackr"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
input: "index.js",
|
|
24
|
+
plugins: [minify({
|
|
25
|
+
})],
|
|
26
|
+
output: {
|
|
27
|
+
file: "dist/index.min.js",
|
|
28
|
+
format: "umd",
|
|
29
|
+
name: "msgpackr"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
input: "tests/test.js",
|
|
34
|
+
plugins: [json()],
|
|
35
|
+
external: ['chai', '../index.js'],
|
|
36
|
+
output: {
|
|
37
|
+
file: "dist/test.js",
|
|
38
|
+
format: "iife",
|
|
39
|
+
globals: {
|
|
40
|
+
chai: 'chai',
|
|
41
|
+
'./index.js': 'msgpackr',
|
|
42
|
+
},
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
];
|
package/stream.js
CHANGED
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
import { Transform } from 'stream'
|
|
2
|
-
import { Packr } from './pack.js'
|
|
3
|
-
import { Unpackr } from './unpack.js'
|
|
4
|
-
var DEFAULT_OPTIONS = {objectMode: true}
|
|
5
|
-
|
|
6
|
-
export class PackrStream extends Transform {
|
|
7
|
-
constructor(options) {
|
|
8
|
-
if (!options)
|
|
9
|
-
options = {}
|
|
10
|
-
options.writableObjectMode = true
|
|
11
|
-
super(options)
|
|
12
|
-
options.sequential = true
|
|
13
|
-
this.packr = options.packr || new Packr(options)
|
|
14
|
-
}
|
|
15
|
-
_transform(value, encoding, callback) {
|
|
16
|
-
this.push(this.packr.pack(value))
|
|
17
|
-
callback()
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export class UnpackrStream extends Transform {
|
|
22
|
-
constructor(options) {
|
|
23
|
-
if (!options)
|
|
24
|
-
options = {}
|
|
25
|
-
options.objectMode = true
|
|
26
|
-
super(options)
|
|
27
|
-
options.structures = []
|
|
28
|
-
this.unpackr = options.unpackr || new Unpackr(options)
|
|
29
|
-
}
|
|
30
|
-
_transform(chunk, encoding, callback) {
|
|
31
|
-
if (this.incompleteBuffer) {
|
|
32
|
-
chunk = Buffer.concat([this.incompleteBuffer, chunk])
|
|
33
|
-
this.incompleteBuffer = null
|
|
34
|
-
}
|
|
35
|
-
let values
|
|
36
|
-
try {
|
|
37
|
-
values = this.unpackr.unpackMultiple(chunk)
|
|
38
|
-
} catch(error) {
|
|
39
|
-
if (error.incomplete) {
|
|
40
|
-
this.incompleteBuffer = chunk.slice(error.lastPosition)
|
|
41
|
-
values = error.values
|
|
42
|
-
}
|
|
43
|
-
else
|
|
44
|
-
throw error
|
|
45
|
-
} finally {
|
|
46
|
-
for (let value of values || []) {
|
|
47
|
-
if (value === null)
|
|
48
|
-
value = this.getNullValue()
|
|
49
|
-
this.push(value)
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
if (callback) callback()
|
|
53
|
-
}
|
|
54
|
-
getNullValue() {
|
|
55
|
-
return Symbol.for(null)
|
|
56
|
-
}
|
|
57
|
-
}
|
|
1
|
+
import { Transform } from 'stream'
|
|
2
|
+
import { Packr } from './pack.js'
|
|
3
|
+
import { Unpackr } from './unpack.js'
|
|
4
|
+
var DEFAULT_OPTIONS = {objectMode: true}
|
|
5
|
+
|
|
6
|
+
export class PackrStream extends Transform {
|
|
7
|
+
constructor(options) {
|
|
8
|
+
if (!options)
|
|
9
|
+
options = {}
|
|
10
|
+
options.writableObjectMode = true
|
|
11
|
+
super(options)
|
|
12
|
+
options.sequential = true
|
|
13
|
+
this.packr = options.packr || new Packr(options)
|
|
14
|
+
}
|
|
15
|
+
_transform(value, encoding, callback) {
|
|
16
|
+
this.push(this.packr.pack(value))
|
|
17
|
+
callback()
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export class UnpackrStream extends Transform {
|
|
22
|
+
constructor(options) {
|
|
23
|
+
if (!options)
|
|
24
|
+
options = {}
|
|
25
|
+
options.objectMode = true
|
|
26
|
+
super(options)
|
|
27
|
+
options.structures = []
|
|
28
|
+
this.unpackr = options.unpackr || new Unpackr(options)
|
|
29
|
+
}
|
|
30
|
+
_transform(chunk, encoding, callback) {
|
|
31
|
+
if (this.incompleteBuffer) {
|
|
32
|
+
chunk = Buffer.concat([this.incompleteBuffer, chunk])
|
|
33
|
+
this.incompleteBuffer = null
|
|
34
|
+
}
|
|
35
|
+
let values
|
|
36
|
+
try {
|
|
37
|
+
values = this.unpackr.unpackMultiple(chunk)
|
|
38
|
+
} catch(error) {
|
|
39
|
+
if (error.incomplete) {
|
|
40
|
+
this.incompleteBuffer = chunk.slice(error.lastPosition)
|
|
41
|
+
values = error.values
|
|
42
|
+
}
|
|
43
|
+
else
|
|
44
|
+
throw error
|
|
45
|
+
} finally {
|
|
46
|
+
for (let value of values || []) {
|
|
47
|
+
if (value === null)
|
|
48
|
+
value = this.getNullValue()
|
|
49
|
+
this.push(value)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (callback) callback()
|
|
53
|
+
}
|
|
54
|
+
getNullValue() {
|
|
55
|
+
return Symbol.for(null)
|
|
56
|
+
}
|
|
57
|
+
}
|
package/unpack.d.ts
CHANGED
|
@@ -1,51 +1,53 @@
|
|
|
1
|
-
export enum FLOAT32_OPTIONS {
|
|
2
|
-
NEVER = 0,
|
|
3
|
-
ALWAYS = 1,
|
|
4
|
-
DECIMAL_ROUND = 3,
|
|
5
|
-
DECIMAL_FIT = 4
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export interface Options {
|
|
9
|
-
useFloat32?: FLOAT32_OPTIONS
|
|
10
|
-
useRecords?: boolean
|
|
11
|
-
structures?: {}[]
|
|
12
|
-
moreTypes?: boolean
|
|
13
|
-
structuredClone?: boolean
|
|
14
|
-
mapsAsObjects?: boolean
|
|
15
|
-
variableMapSize?: boolean
|
|
16
|
-
copyBuffers?: boolean
|
|
17
|
-
bundleStrings?: boolean
|
|
18
|
-
useTimestamp32?: boolean
|
|
19
|
-
largeBigIntToFloat?: boolean
|
|
20
|
-
encodeUndefinedAsNil?: boolean
|
|
21
|
-
maxSharedStructures?: number
|
|
22
|
-
maxOwnStructures?: number
|
|
23
|
-
int64AsNumber?: boolean
|
|
24
|
-
shouldShareStructure?: (keys: string[]) => boolean
|
|
25
|
-
getStructures?(): {}[]
|
|
26
|
-
saveStructures?(structures: {}[]): boolean | void
|
|
27
|
-
onInvalidDate?: () => any
|
|
28
|
-
}
|
|
29
|
-
interface Extension {
|
|
30
|
-
Class: Function
|
|
31
|
-
type: number
|
|
32
|
-
pack?(value: any): Buffer | Uint8Array
|
|
33
|
-
unpack?(messagePack: Buffer | Uint8Array): any
|
|
34
|
-
read?(datum: any): any
|
|
35
|
-
write?(instance: any): any
|
|
36
|
-
}
|
|
37
|
-
export class Unpackr {
|
|
38
|
-
constructor(options?: Options)
|
|
39
|
-
unpack(messagePack: Buffer | Uint8Array): any
|
|
40
|
-
decode(messagePack: Buffer | Uint8Array): any
|
|
41
|
-
unpackMultiple(messagePack: Buffer | Uint8Array
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
export
|
|
45
|
-
export function
|
|
46
|
-
export function
|
|
47
|
-
export function
|
|
48
|
-
export function
|
|
49
|
-
export function
|
|
50
|
-
export
|
|
1
|
+
export enum FLOAT32_OPTIONS {
|
|
2
|
+
NEVER = 0,
|
|
3
|
+
ALWAYS = 1,
|
|
4
|
+
DECIMAL_ROUND = 3,
|
|
5
|
+
DECIMAL_FIT = 4
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface Options {
|
|
9
|
+
useFloat32?: FLOAT32_OPTIONS
|
|
10
|
+
useRecords?: boolean
|
|
11
|
+
structures?: {}[]
|
|
12
|
+
moreTypes?: boolean
|
|
13
|
+
structuredClone?: boolean
|
|
14
|
+
mapsAsObjects?: boolean
|
|
15
|
+
variableMapSize?: boolean
|
|
16
|
+
copyBuffers?: boolean
|
|
17
|
+
bundleStrings?: boolean
|
|
18
|
+
useTimestamp32?: boolean
|
|
19
|
+
largeBigIntToFloat?: boolean
|
|
20
|
+
encodeUndefinedAsNil?: boolean
|
|
21
|
+
maxSharedStructures?: number
|
|
22
|
+
maxOwnStructures?: number
|
|
23
|
+
int64AsNumber?: boolean
|
|
24
|
+
shouldShareStructure?: (keys: string[]) => boolean
|
|
25
|
+
getStructures?(): {}[]
|
|
26
|
+
saveStructures?(structures: {}[]): boolean | void
|
|
27
|
+
onInvalidDate?: () => any
|
|
28
|
+
}
|
|
29
|
+
interface Extension {
|
|
30
|
+
Class: Function
|
|
31
|
+
type: number
|
|
32
|
+
pack?(value: any): Buffer | Uint8Array
|
|
33
|
+
unpack?(messagePack: Buffer | Uint8Array): any
|
|
34
|
+
read?(datum: any): any
|
|
35
|
+
write?(instance: any): any
|
|
36
|
+
}
|
|
37
|
+
export class Unpackr {
|
|
38
|
+
constructor(options?: Options)
|
|
39
|
+
unpack(messagePack: Buffer | Uint8Array): any
|
|
40
|
+
decode(messagePack: Buffer | Uint8Array): any
|
|
41
|
+
unpackMultiple(messagePack: Buffer | Uint8Array): any[]
|
|
42
|
+
unpackMultiple(messagePack: Buffer | Uint8Array, forEach: (value: any) => any): void
|
|
43
|
+
}
|
|
44
|
+
export class Decoder extends Unpackr {}
|
|
45
|
+
export function unpack(messagePack: Buffer | Uint8Array): any
|
|
46
|
+
export function unpackMultiple(messagePack: Buffer | Uint8Array): any[]
|
|
47
|
+
export function unpackMultiple(messagePack: Buffer | Uint8Array, forEach: (value: any) => any): void
|
|
48
|
+
export function decode(messagePack: Buffer | Uint8Array): any
|
|
49
|
+
export function addExtension(extension: Extension): void
|
|
50
|
+
export function clearSource(): void
|
|
51
|
+
export function roundFloat32(float32Number: number): number
|
|
52
|
+
export const C1: {}
|
|
51
53
|
export let isNativeAccelerationEnabled: boolean
|