11# [ json-bufferify] ( https://github.com/LangZhai/json-bufferify ) [ ![ Travis (.org)] ( https://img.shields.io/travis/LangZhai/json-bufferify )] ( https://travis-ci.org/LangZhai/json-bufferify/builds ) [ ![ npm] ( https://img.shields.io/npm/v/json-bufferify )] ( https://www.npmjs.com/package/json-bufferify ) ![ GitHub file size in bytes] ( https://img.shields.io/github/size/LangZhai/json-bufferify/dist/json-bufferify.min.js )
22
3- This is a module to help you convert between JSON and ArrayBuffer, and you can run it in both Node.js and browser .
3+ This is a tiny module to help you convert between JSON data and ArrayBuffer, and you can use it in both Node.js and browsers .
44
55## Feature
66
7- * Convert JSON to ArrayBuffer.
8- * Revert ArrayBuffer to JSON .
7+ * Convert JSON data to ArrayBuffer.
8+ * Revert JSON data from ArrayBuffer .
99
1010## Installation
1111
@@ -15,15 +15,23 @@ npm install json-bufferify
1515
1616## Usage
1717
18- ### Require json-bufferify.
18+ ### Import json-bufferify.
1919
2020__ In Node.js__
2121
22+ CommonJS
23+
2224``` javascript
23- var bufferify = require (' json-bufferify' );
25+ const bufferify = require (' json-bufferify' );
2426```
2527
26- __ In browser__
28+ ES6 Modules
29+
30+ ``` javascript
31+ import bufferify from ' json-bufferify' ;
32+ ```
33+
34+ __ In browsers__
2735
2836``` html
2937<script src =" json-bufferify.js" ></script >
@@ -46,10 +54,10 @@ Open "egretProperties.json" and Add the following code to "modules" node.
4654}
4755```
4856
49- ### Convert JSON to ArrayBuffer and send by WebSocket.
57+ ### Convert JSON data to ArrayBuffer and send via WebSocket.
5058
5159``` javascript
52- var ws = new WebSocket (url);
60+ let ws = new WebSocket (url);
5361ws .binaryType = ' arraybuffer' ;
5462ws .send (bufferify .encode (0 , {
5563 sex: 0 ,
@@ -58,7 +66,7 @@ ws.send(bufferify.encode(0, {
5866}));
5967```
6068
61- ### Revert ArrayBuffer to JSON .
69+ ### Revert JSON data from ArrayBuffer .
6270
6371``` javascript
6472ws .on (' message' , data => {
@@ -70,29 +78,29 @@ ws.on('message', data => {
7078});
7179```
7280
73- ## Documentation
81+ ## API
7482
7583### bufferify.encode(offset, data)
7684
77- Convert JSON to ArrayBuffer and return the DataView.
85+ Convert JSON data to ArrayBuffer and return the DataView.
7886
79- * ` offset ` - The start of the DataView where to store the data.
87+ * ` offset ` - The start point of the DataView where to store the data.
8088* ` data ` - The JSON data.
8189
8290### bufferify.decode(offset, template, source)
8391
84- Revert ArrayBuffer to JSON data and return it.
92+ Revert JSON data from ArrayBuffer and return it.
8593
86- * ` offset ` - The start of the DataView where to read the data.
87- * ` template ` - The template of the JSON.
94+ * ` offset ` - The start point of the DataView where to read the data.
95+ * ` template ` - The template of the JSON data .
8896* ` source ` - The ArrayBuffer, or the Buffer in Node.js, or the DataView of the ArrayBuffer.
8997
9098## Example
9199
92100### Convert/Revert an array.
93101
94102``` javascript
95- var ws = new WebSocket (url);
103+ let ws = new WebSocket (url);
96104ws .binaryType = ' arraybuffer' ;
97105ws .send (bufferify .encode (0 , [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ]));
98106```
@@ -106,7 +114,7 @@ ws.on('message', data => {
106114### Convert/Revert a complex Object.
107115
108116``` javascript
109- var ws = new WebSocket (url);
117+ let ws = new WebSocket (url);
110118ws .binaryType = ' arraybuffer' ;
111119ws .send (bufferify .encode (0 , {
112120 obj: {
@@ -145,6 +153,11 @@ ws.on('message', data => {
145153});
146154```
147155
156+ ## Compatibility
157+
158+ * The latest LTS version of Node.js.
159+ * Modern browsers such as Chrome, Firefox, Edge(Chromium-based), Safari.
160+
148161## License [ ![ NPM] ( https://img.shields.io/npm/l/json-bufferify )] ( https://github.com/LangZhai/json-bufferify/blob/master/LICENSE )
149162
150163This is licensed under the GNU LGPL, version 3 or later.
0 commit comments