Skip to content

Commit e99653b

Browse files
Update README.md
1 parent 4e9787d commit e99653b

File tree

1 file changed

+30
-17
lines changed

1 file changed

+30
-17
lines changed

README.md

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
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);
5361
ws.binaryType = 'arraybuffer';
5462
ws.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
6472
ws.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);
96104
ws.binaryType = 'arraybuffer';
97105
ws.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);
110118
ws.binaryType = 'arraybuffer';
111119
ws.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

150163
This is licensed under the GNU LGPL, version 3 or later.

0 commit comments

Comments
 (0)