@ohos-ports/stdlib-buffer 0.0.0-stage → 0.4.1-beta.0
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 +177 -0
- package/NOTICE +1 -0
- package/README.md +205 -2
- package/SECURITY.md +5 -0
- package/alloc-unsafe/README.md +140 -0
- package/alloc-unsafe/docs/repl.txt +28 -0
- package/alloc-unsafe/docs/types/index.d.ts +47 -0
- package/alloc-unsafe/docs/types/test.ts +44 -0
- package/alloc-unsafe/lib/has_alloc_unsafe.js +34 -0
- package/alloc-unsafe/lib/index.js +52 -0
- package/alloc-unsafe/lib/main.js +56 -0
- package/alloc-unsafe/lib/polyfill.js +56 -0
- package/alloc-unsafe/package.json +67 -0
- package/ctor/README.md +182 -0
- package/ctor/docs/repl.txt +91 -0
- package/ctor/docs/types/index.d.ts +37 -0
- package/ctor/docs/types/test.ts +35 -0
- package/ctor/lib/index.js +52 -0
- package/ctor/lib/main.js +28 -0
- package/ctor/lib/polyfill.js +37 -0
- package/ctor/package.json +62 -0
- package/docs/types/index.d.ts +189 -0
- package/from-array/README.md +141 -0
- package/from-array/docs/repl.txt +22 -0
- package/from-array/docs/types/index.d.ts +42 -0
- package/from-array/docs/types/test.ts +42 -0
- package/from-array/lib/has_from.js +34 -0
- package/from-array/lib/index.js +52 -0
- package/from-array/lib/main.js +53 -0
- package/from-array/lib/polyfill.js +53 -0
- package/from-array/package.json +69 -0
- package/from-arraybuffer/README.md +198 -0
- package/from-arraybuffer/docs/repl.txt +48 -0
- package/from-arraybuffer/docs/types/index.d.ts +64 -0
- package/from-arraybuffer/docs/types/test.ts +72 -0
- package/from-arraybuffer/lib/has_from.js +35 -0
- package/from-arraybuffer/lib/index.js +54 -0
- package/from-arraybuffer/lib/main.js +105 -0
- package/from-arraybuffer/lib/node_version.js +33 -0
- package/from-arraybuffer/lib/polyfill.js +107 -0
- package/from-arraybuffer/package.json +69 -0
- package/from-buffer/README.md +145 -0
- package/from-buffer/docs/repl.txt +23 -0
- package/from-buffer/docs/types/index.d.ts +45 -0
- package/from-buffer/docs/types/test.ts +47 -0
- package/from-buffer/lib/has_from.js +34 -0
- package/from-buffer/lib/index.js +56 -0
- package/from-buffer/lib/main.js +56 -0
- package/from-buffer/lib/polyfill.js +56 -0
- package/from-buffer/package.json +67 -0
- package/from-string/README.md +158 -0
- package/from-string/docs/repl.txt +28 -0
- package/from-string/docs/types/index.d.ts +42 -0
- package/from-string/docs/types/test.ts +55 -0
- package/from-string/lib/has_from.js +34 -0
- package/from-string/lib/index.js +52 -0
- package/from-string/lib/main.js +60 -0
- package/from-string/lib/polyfill.js +60 -0
- package/from-string/package.json +66 -0
- package/lib/index.js +114 -0
- package/package.json +63 -4
- package/reviver/README.md +137 -0
- package/reviver/docs/repl.txt +32 -0
- package/reviver/docs/types/index.d.ts +41 -0
- package/reviver/docs/types/test.ts +49 -0
- package/reviver/lib/index.js +43 -0
- package/reviver/lib/main.js +58 -0
- package/reviver/package.json +73 -0
- package/to-json/README.md +142 -0
- package/to-json/docs/repl.txt +31 -0
- package/to-json/docs/types/index.d.ts +46 -0
- package/to-json/docs/types/test.ts +47 -0
- package/to-json/lib/index.js +44 -0
- package/to-json/lib/main.js +63 -0
- package/to-json/package.json +69 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stdlib/buffer/from-string",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Allocate a buffer containing a provided string.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "The Stdlib Authors",
|
|
8
|
+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
|
|
9
|
+
},
|
|
10
|
+
"contributors": [
|
|
11
|
+
{
|
|
12
|
+
"name": "The Stdlib Authors",
|
|
13
|
+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
|
|
14
|
+
}
|
|
15
|
+
],
|
|
16
|
+
"main": "./lib",
|
|
17
|
+
"directories": {
|
|
18
|
+
"benchmark": "./benchmark",
|
|
19
|
+
"doc": "./docs",
|
|
20
|
+
"example": "./examples",
|
|
21
|
+
"lib": "./lib",
|
|
22
|
+
"test": "./test"
|
|
23
|
+
},
|
|
24
|
+
"types": "./docs/types",
|
|
25
|
+
"scripts": {},
|
|
26
|
+
"homepage": "https://github.com/stdlib-js/stdlib",
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "git://github.com/stdlib-js/stdlib.git"
|
|
30
|
+
},
|
|
31
|
+
"bugs": {
|
|
32
|
+
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {},
|
|
35
|
+
"devDependencies": {},
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=0.10.0",
|
|
38
|
+
"npm": ">2.7.0"
|
|
39
|
+
},
|
|
40
|
+
"os": [
|
|
41
|
+
"aix",
|
|
42
|
+
"darwin",
|
|
43
|
+
"freebsd",
|
|
44
|
+
"linux",
|
|
45
|
+
"macos",
|
|
46
|
+
"openbsd",
|
|
47
|
+
"openharmony",
|
|
48
|
+
"sunos",
|
|
49
|
+
"win32",
|
|
50
|
+
"windows"
|
|
51
|
+
],
|
|
52
|
+
"keywords": [
|
|
53
|
+
"stdlib",
|
|
54
|
+
"stdtypes",
|
|
55
|
+
"types",
|
|
56
|
+
"data",
|
|
57
|
+
"structure",
|
|
58
|
+
"buffer",
|
|
59
|
+
"buf",
|
|
60
|
+
"binary",
|
|
61
|
+
"octets",
|
|
62
|
+
"string",
|
|
63
|
+
"str",
|
|
64
|
+
"allocate"
|
|
65
|
+
]
|
|
66
|
+
}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2021 The Stdlib Authors.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
'use strict';
|
|
20
|
+
|
|
21
|
+
/*
|
|
22
|
+
* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
// MODULES //
|
|
26
|
+
|
|
27
|
+
var setReadOnly = require( '@stdlib/utils/define-read-only-property' );
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
// MAIN //
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Top-level namespace.
|
|
34
|
+
*
|
|
35
|
+
* @namespace ns
|
|
36
|
+
*/
|
|
37
|
+
var ns = {};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @name allocUnsafe
|
|
41
|
+
* @memberof ns
|
|
42
|
+
* @readonly
|
|
43
|
+
* @type {Function}
|
|
44
|
+
* @see {@link module:@stdlib/buffer/alloc-unsafe}
|
|
45
|
+
*/
|
|
46
|
+
setReadOnly( ns, 'allocUnsafe', require( './../alloc-unsafe' ) );
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @name Buffer
|
|
50
|
+
* @memberof ns
|
|
51
|
+
* @readonly
|
|
52
|
+
* @type {Function}
|
|
53
|
+
* @see {@link module:@stdlib/buffer/ctor}
|
|
54
|
+
*/
|
|
55
|
+
setReadOnly( ns, 'Buffer', require( './../ctor' ) );
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @name array2buffer
|
|
59
|
+
* @memberof ns
|
|
60
|
+
* @readonly
|
|
61
|
+
* @type {Function}
|
|
62
|
+
* @see {@link module:@stdlib/buffer/from-arraybuffer}
|
|
63
|
+
*/
|
|
64
|
+
setReadOnly( ns, 'array2buffer', require( './../from-array' ) );
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* @name arraybuffer2buffer
|
|
68
|
+
* @memberof ns
|
|
69
|
+
* @readonly
|
|
70
|
+
* @type {Function}
|
|
71
|
+
* @see {@link module:@stdlib/buffer/from-arraybuffer}
|
|
72
|
+
*/
|
|
73
|
+
setReadOnly( ns, 'arraybuffer2buffer', require( './../from-arraybuffer' ) );
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* @name copyBuffer
|
|
77
|
+
* @memberof ns
|
|
78
|
+
* @readonly
|
|
79
|
+
* @type {Function}
|
|
80
|
+
* @see {@link module:@stdlib/buffer/from-buffer}
|
|
81
|
+
*/
|
|
82
|
+
setReadOnly( ns, 'copyBuffer', require( './../from-buffer' ) );
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* @name string2buffer
|
|
86
|
+
* @memberof ns
|
|
87
|
+
* @readonly
|
|
88
|
+
* @type {Function}
|
|
89
|
+
* @see {@link module:@stdlib/buffer/from-string}
|
|
90
|
+
*/
|
|
91
|
+
setReadOnly( ns, 'string2buffer', require( './../from-string' ) );
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @name reviveBuffer
|
|
95
|
+
* @memberof ns
|
|
96
|
+
* @readonly
|
|
97
|
+
* @type {Function}
|
|
98
|
+
* @see {@link module:@stdlib/buffer/reviver}
|
|
99
|
+
*/
|
|
100
|
+
setReadOnly( ns, 'reviveBuffer', require( './../reviver' ) );
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* @name buffer2json
|
|
104
|
+
* @memberof ns
|
|
105
|
+
* @readonly
|
|
106
|
+
* @type {Function}
|
|
107
|
+
* @see {@link module:@stdlib/buffer/to-json}
|
|
108
|
+
*/
|
|
109
|
+
setReadOnly( ns, 'buffer2json', require( './../to-json' ) );
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
// EXPORTS //
|
|
113
|
+
|
|
114
|
+
module.exports = ns;
|
package/package.json
CHANGED
|
@@ -1,6 +1,65 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ohos-ports/stdlib-buffer",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.4.1-beta.0",
|
|
4
|
+
"description": "Buffer.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "The Stdlib Authors",
|
|
8
|
+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
|
|
9
|
+
},
|
|
10
|
+
"contributors": [
|
|
11
|
+
{
|
|
12
|
+
"name": "The Stdlib Authors",
|
|
13
|
+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
|
|
14
|
+
}
|
|
15
|
+
],
|
|
16
|
+
"main": "./lib",
|
|
17
|
+
"directories": {
|
|
18
|
+
"doc": "./docs",
|
|
19
|
+
"lib": "./lib"
|
|
20
|
+
},
|
|
21
|
+
"types": "./docs/types",
|
|
22
|
+
"scripts": {},
|
|
23
|
+
"homepage": "https://stdlib.io",
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "https://github.com/ohos-ports/ohos-ports.git",
|
|
27
|
+
"directory": "ports/stdlib-buffer/0.4.1"
|
|
28
|
+
},
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/ohos-ports/ohos-ports/issues"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@stdlib/array": "^0.5.0",
|
|
34
|
+
"@stdlib/assert": "^0.4.0",
|
|
35
|
+
"@stdlib/process": "^0.4.0",
|
|
36
|
+
"@stdlib/string": "^0.4.0",
|
|
37
|
+
"@stdlib/types": "^0.5.0",
|
|
38
|
+
"@stdlib/utils": "^0.4.0"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {},
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=0.10.0",
|
|
43
|
+
"npm": ">2.7.0"
|
|
44
|
+
},
|
|
45
|
+
"os": [
|
|
46
|
+
"aix",
|
|
47
|
+
"darwin",
|
|
48
|
+
"freebsd",
|
|
49
|
+
"linux",
|
|
50
|
+
"macos",
|
|
51
|
+
"openbsd",
|
|
52
|
+
"openharmony",
|
|
53
|
+
"sunos",
|
|
54
|
+
"win32",
|
|
55
|
+
"windows"
|
|
56
|
+
],
|
|
57
|
+
"keywords": [
|
|
58
|
+
"stdlib",
|
|
59
|
+
"buffer"
|
|
60
|
+
],
|
|
61
|
+
"funding": {
|
|
62
|
+
"type": "opencollective",
|
|
63
|
+
"url": "https://opencollective.com/stdlib"
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
|
|
3
|
+
@license Apache-2.0
|
|
4
|
+
|
|
5
|
+
Copyright (c) 2018 The Stdlib Authors.
|
|
6
|
+
|
|
7
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
you may not use this file except in compliance with the License.
|
|
9
|
+
You may obtain a copy of the License at
|
|
10
|
+
|
|
11
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
|
|
13
|
+
Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
See the License for the specific language governing permissions and
|
|
17
|
+
limitations under the License.
|
|
18
|
+
|
|
19
|
+
-->
|
|
20
|
+
|
|
21
|
+
# reviveBuffer
|
|
22
|
+
|
|
23
|
+
> Revive a JSON-serialized [Buffer][@stdlib/buffer/ctor].
|
|
24
|
+
|
|
25
|
+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
|
|
26
|
+
|
|
27
|
+
<section class="intro">
|
|
28
|
+
|
|
29
|
+
</section>
|
|
30
|
+
|
|
31
|
+
<!-- /.intro -->
|
|
32
|
+
|
|
33
|
+
<!-- Package usage documentation. -->
|
|
34
|
+
|
|
35
|
+
<section class="usage">
|
|
36
|
+
|
|
37
|
+
## Usage
|
|
38
|
+
|
|
39
|
+
```javascript
|
|
40
|
+
var reviveBuffer = require( '@stdlib/buffer/reviver' );
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
#### reviveBuffer( key, value )
|
|
44
|
+
|
|
45
|
+
Revives a JSON-serialized [`Buffer`][@stdlib/buffer/ctor].
|
|
46
|
+
|
|
47
|
+
```javascript
|
|
48
|
+
var parseJSON = require( '@stdlib/utils/parse-json' );
|
|
49
|
+
|
|
50
|
+
var str = '{"type":"Buffer","data":[5,3]}';
|
|
51
|
+
|
|
52
|
+
var buf = parseJSON( str, reviveBuffer );
|
|
53
|
+
// returns <Buffer>[ 5, 3 ]
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
For details on the JSON serialization format, see [`@stdlib/buffer/to-json`][@stdlib/buffer/to-json].
|
|
57
|
+
|
|
58
|
+
</section>
|
|
59
|
+
|
|
60
|
+
<!-- /.usage -->
|
|
61
|
+
|
|
62
|
+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
63
|
+
|
|
64
|
+
<section class="notes">
|
|
65
|
+
|
|
66
|
+
</section>
|
|
67
|
+
|
|
68
|
+
<!-- /.notes -->
|
|
69
|
+
|
|
70
|
+
<!-- Package usage examples. -->
|
|
71
|
+
|
|
72
|
+
<section class="examples">
|
|
73
|
+
|
|
74
|
+
## Examples
|
|
75
|
+
|
|
76
|
+
<!-- eslint no-undef: "error" -->
|
|
77
|
+
|
|
78
|
+
```javascript
|
|
79
|
+
var array2buffer = require( '@stdlib/buffer/from-array' );
|
|
80
|
+
var parseJSON = require( '@stdlib/utils/parse-json' );
|
|
81
|
+
var buffer2json = require( '@stdlib/buffer/to-json' );
|
|
82
|
+
var reviveBuffer = require( '@stdlib/buffer/reviver' );
|
|
83
|
+
|
|
84
|
+
var buf = array2buffer( [ 1, 2 ] );
|
|
85
|
+
var str = JSON.stringify( buffer2json( buf ) );
|
|
86
|
+
console.log( str );
|
|
87
|
+
// => '{"type":"Buffer","data":[1,2]}'
|
|
88
|
+
|
|
89
|
+
var out = parseJSON( str, reviveBuffer );
|
|
90
|
+
if ( out instanceof Error ) {
|
|
91
|
+
throw out;
|
|
92
|
+
}
|
|
93
|
+
console.log( out );
|
|
94
|
+
// => <Buffer>[ 1, 2 ]
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
</section>
|
|
98
|
+
|
|
99
|
+
<!-- /.examples -->
|
|
100
|
+
|
|
101
|
+
<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
102
|
+
|
|
103
|
+
<section class="references">
|
|
104
|
+
|
|
105
|
+
</section>
|
|
106
|
+
|
|
107
|
+
<!-- /.references -->
|
|
108
|
+
|
|
109
|
+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
|
|
110
|
+
|
|
111
|
+
<section class="related">
|
|
112
|
+
|
|
113
|
+
* * *
|
|
114
|
+
|
|
115
|
+
## See Also
|
|
116
|
+
|
|
117
|
+
- <span class="package-name">[`@stdlib/buffer/to-json`][@stdlib/buffer/to-json]</span><span class="delimiter">: </span><span class="description">return a JSON representation of a Buffer.</span>
|
|
118
|
+
|
|
119
|
+
</section>
|
|
120
|
+
|
|
121
|
+
<!-- /.related -->
|
|
122
|
+
|
|
123
|
+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
124
|
+
|
|
125
|
+
<section class="links">
|
|
126
|
+
|
|
127
|
+
[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer/tree/main/ctor
|
|
128
|
+
|
|
129
|
+
[@stdlib/buffer/to-json]: https://github.com/stdlib-js/buffer/tree/main/to-json
|
|
130
|
+
|
|
131
|
+
<!-- <related-links> -->
|
|
132
|
+
|
|
133
|
+
<!-- </related-links> -->
|
|
134
|
+
|
|
135
|
+
</section>
|
|
136
|
+
|
|
137
|
+
<!-- /.links -->
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
|
|
2
|
+
{{alias}}( key, value )
|
|
3
|
+
Revives a JSON-serialized Buffer.
|
|
4
|
+
|
|
5
|
+
The serialization format for a Buffer is an object having the following
|
|
6
|
+
fields:
|
|
7
|
+
|
|
8
|
+
- type: value type (Buffer).
|
|
9
|
+
- data: buffer data as an array of integers.
|
|
10
|
+
|
|
11
|
+
Parameters
|
|
12
|
+
----------
|
|
13
|
+
key: string
|
|
14
|
+
Key.
|
|
15
|
+
|
|
16
|
+
value: any
|
|
17
|
+
Value.
|
|
18
|
+
|
|
19
|
+
Returns
|
|
20
|
+
-------
|
|
21
|
+
out: any
|
|
22
|
+
Value or Buffer.
|
|
23
|
+
|
|
24
|
+
Examples
|
|
25
|
+
--------
|
|
26
|
+
> var str = '{"type":"Buffer","data":[5,3]}';
|
|
27
|
+
> var buf = {{alias:@stdlib/utils/parse-json}}( str, {{alias}} )
|
|
28
|
+
<Buffer>[ 5, 3 ]
|
|
29
|
+
|
|
30
|
+
See Also
|
|
31
|
+
--------
|
|
32
|
+
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2021 The Stdlib Authors.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
// TypeScript Version: 4.1
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Revives a JSON-serialized `Buffer`.
|
|
23
|
+
*
|
|
24
|
+
* @param key - key
|
|
25
|
+
* @param value - value
|
|
26
|
+
* @returns value or Buffer
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* var parseJSON = require( '@stdlib/utils/parse-json' );
|
|
30
|
+
*
|
|
31
|
+
* var str = '{"type":"Buffer","data":[5,3]}';
|
|
32
|
+
*
|
|
33
|
+
* var buf = parseJSON( str, reviveBuffer );
|
|
34
|
+
* // returns <Buffer>[ 5, 3 ]
|
|
35
|
+
*/
|
|
36
|
+
declare function reviveBuffer( key: string, value: any ): any;
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
// EXPORTS //
|
|
40
|
+
|
|
41
|
+
export = reviveBuffer;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2021 The Stdlib Authors.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import reviveBuffer = require( './index' );
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
// TESTS //
|
|
23
|
+
|
|
24
|
+
// The function revives a serialized object...
|
|
25
|
+
{
|
|
26
|
+
const o = {
|
|
27
|
+
'type': 'Buffer',
|
|
28
|
+
'data': [ 5, 3 ]
|
|
29
|
+
};
|
|
30
|
+
reviveBuffer( 'foo', o ); // $ExpectType any
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// The compiler throws an error if the function is provided a first argument that is not a string...
|
|
34
|
+
{
|
|
35
|
+
reviveBuffer( true, 1 ); // $ExpectError
|
|
36
|
+
reviveBuffer( false, 1 ); // $ExpectError
|
|
37
|
+
reviveBuffer( null, 1 ); // $ExpectError
|
|
38
|
+
reviveBuffer( undefined, 1 ); // $ExpectError
|
|
39
|
+
reviveBuffer( 5, 1 ); // $ExpectError
|
|
40
|
+
reviveBuffer( [], 1 ); // $ExpectError
|
|
41
|
+
reviveBuffer( {}, 1 ); // $ExpectError
|
|
42
|
+
reviveBuffer( ( x: number ): number => x, 1 ); // $ExpectError
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// The compiler throws an error if the function is provided insufficient arguments...
|
|
46
|
+
{
|
|
47
|
+
reviveBuffer(); // $ExpectError
|
|
48
|
+
reviveBuffer( '{"type":"Buffer","data":[5,3]}' ); // $ExpectError
|
|
49
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2018 The Stdlib Authors.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
'use strict';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Revive a JSON-serialized `Buffer`.
|
|
23
|
+
*
|
|
24
|
+
* @module @stdlib/buffer/reviver
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* var parseJSON = require( '@stdlib/utils/parse-json' );
|
|
28
|
+
* var reviveBuffer = require( '@stdlib/buffer/reviver' );
|
|
29
|
+
*
|
|
30
|
+
* var str = '{"type":"Buffer","data":[5,3]}';
|
|
31
|
+
*
|
|
32
|
+
* var buf = parseJSON( str, reviveBuffer );
|
|
33
|
+
* // returns <Buffer>[ 5, 3 ]
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
// MODULES //
|
|
37
|
+
|
|
38
|
+
var main = require( './main.js' );
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
// EXPORTS //
|
|
42
|
+
|
|
43
|
+
module.exports = main;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2018 The Stdlib Authors.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
'use strict';
|
|
20
|
+
|
|
21
|
+
// MODULES //
|
|
22
|
+
|
|
23
|
+
var isArray = require( '@stdlib/assert/is-array' );
|
|
24
|
+
var array2buffer = require( './../../from-array' );
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
// MAIN //
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Revives a JSON-serialized `Buffer`.
|
|
31
|
+
*
|
|
32
|
+
* @param {string} key - key
|
|
33
|
+
* @param {*} value - value
|
|
34
|
+
* @returns {(*|Buffer)} value or Buffer
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* var parseJSON = require( '@stdlib/utils/parse-json' );
|
|
38
|
+
*
|
|
39
|
+
* var str = '{"type":"Buffer","data":[5,3]}';
|
|
40
|
+
*
|
|
41
|
+
* var buf = parseJSON( str, reviver );
|
|
42
|
+
* // returns <Buffer>[ 5, 3 ]
|
|
43
|
+
*/
|
|
44
|
+
function reviver( key, value ) {
|
|
45
|
+
if (
|
|
46
|
+
value &&
|
|
47
|
+
value.type === 'Buffer' &&
|
|
48
|
+
isArray( value.data )
|
|
49
|
+
) {
|
|
50
|
+
return array2buffer( value.data );
|
|
51
|
+
}
|
|
52
|
+
return value;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
// EXPORTS //
|
|
57
|
+
|
|
58
|
+
module.exports = reviver;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stdlib/buffer/reviver",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Revive a JSON-serialized Buffer.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "The Stdlib Authors",
|
|
8
|
+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
|
|
9
|
+
},
|
|
10
|
+
"contributors": [
|
|
11
|
+
{
|
|
12
|
+
"name": "The Stdlib Authors",
|
|
13
|
+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
|
|
14
|
+
}
|
|
15
|
+
],
|
|
16
|
+
"main": "./lib",
|
|
17
|
+
"directories": {
|
|
18
|
+
"benchmark": "./benchmark",
|
|
19
|
+
"doc": "./docs",
|
|
20
|
+
"example": "./examples",
|
|
21
|
+
"lib": "./lib",
|
|
22
|
+
"test": "./test"
|
|
23
|
+
},
|
|
24
|
+
"types": "./docs/types",
|
|
25
|
+
"scripts": {},
|
|
26
|
+
"homepage": "https://github.com/stdlib-js/stdlib",
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "git://github.com/stdlib-js/stdlib.git"
|
|
30
|
+
},
|
|
31
|
+
"bugs": {
|
|
32
|
+
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {},
|
|
35
|
+
"devDependencies": {},
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=0.10.0",
|
|
38
|
+
"npm": ">2.7.0"
|
|
39
|
+
},
|
|
40
|
+
"os": [
|
|
41
|
+
"aix",
|
|
42
|
+
"darwin",
|
|
43
|
+
"freebsd",
|
|
44
|
+
"linux",
|
|
45
|
+
"macos",
|
|
46
|
+
"openbsd",
|
|
47
|
+
"openharmony",
|
|
48
|
+
"sunos",
|
|
49
|
+
"win32",
|
|
50
|
+
"windows"
|
|
51
|
+
],
|
|
52
|
+
"keywords": [
|
|
53
|
+
"stdlib",
|
|
54
|
+
"stdtypes",
|
|
55
|
+
"utils",
|
|
56
|
+
"util",
|
|
57
|
+
"utilities",
|
|
58
|
+
"utility",
|
|
59
|
+
"buffer",
|
|
60
|
+
"buf",
|
|
61
|
+
"binary",
|
|
62
|
+
"json",
|
|
63
|
+
"reviver",
|
|
64
|
+
"revive",
|
|
65
|
+
"unmarshal",
|
|
66
|
+
"deserialize",
|
|
67
|
+
"from",
|
|
68
|
+
"convert",
|
|
69
|
+
"parse",
|
|
70
|
+
"object",
|
|
71
|
+
"obj"
|
|
72
|
+
]
|
|
73
|
+
}
|