blob: e95d2b94014da0b84a18737b541b22908ee1aa99 (
about) (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
# chromium-pickle-js [](https://travis-ci.org/electron/node-chromium-pickle-js)
This module ports Chromium's `Pickle` class to Node, see `Pickle`'s header for
introduction:
> This class provides facilities for basic binary value packing and unpacking.
>
> The Pickle class supports appending primitive values (ints, strings, etc.)
> to a pickle instance. The Pickle instance grows its internal memory buffer
> dynamically to hold the sequence of primitive values. The internal memory
> buffer is exposed as the "data" of the Pickle. This "data" can be passed
> to a Pickle object to initialize it for reading.
>
> When reading from a Pickle object, it is important for the consumer to know
> what value types to read and in what order to read them as the Pickle does
> not keep track of the type of data written to it.
>
> The Pickle's data has a header which contains the size of the Pickle's
> payload. It can optionally support additional space in the header. That
> space is controlled by the header_size parameter passed to the Pickle
> constructor.
## Install
```bash
$ npm install chromium-pickle-js
```
## Usage
### createEmpty()
Returns an empty `Pickle` object.
### createFromBuffer(buffer)
* `buffer` Buffer
Returns a `Pickle` object that initialized from a `buffer`. The data is not
copied so you have to ensure the `buffer` lives when using the Pickle object,
and you should never modify the Pickle object created this way.
### Pickle.createIterator()
Returns a `PickleIterator` object that can be used to read data from this
`Pickle` object.
### Pickle.toBuffer()
Returns a `Buffer` object that contains this `Pickle` object's data.
### Pickle.writeBool(value)
Writes `value` to `Pickle` object as `bool`. Returns `true` when succeeded and
returns `false` when failed.
### Pickle.writeInt(value)
Writes `value` to `Pickle` object as `int`. Returns `true` when succeeded and
returns `false` when failed.
### Pickle.writeUInt32(value)
Writes `value` to `Pickle` object as `uint32`. Returns `true` when succeeded and
returns `false` when failed.
### Pickle.writeInt64(value)
Writes `value` to `Pickle` object as `int64`. Returns `true` when succeeded and
returns `false` when failed.
### Pickle.writeUInt64(value)
Writes `value` to `Pickle` object as `uint64`. Returns `true` when succeeded and
returns `false` when failed.
### Pickle.writeFloat(value)
Writes `value` to `Pickle` object as `float`. Returns `true` when succeeded and
returns `false` when failed.
### Pickle.writeDouble(value)
Writes `value` to `Pickle` object as `Double`. Returns `true` when succeeded and
returns `false` when failed.
### Pickle.writeString(str)
* `str` String
Writes `str` to `Pickle` object. Returns `true` when succeeded and returns
`false` when failed.
### PickleIterator.readBool()
Returns current value as `bool` and seeks to next data. A`TypeError` exception
would be thrown when failed.
### PickleIterator.readInt()
Returns current value as `int` and seeks to next data. A`TypeError` exception
would be thrown when failed.
### PickleIterator.readUInt32()
Returns current value as `uint32` and seeks to next data. A`TypeError` exception
would be thrown when failed.
### PickleIterator.readInt64()
Returns current value as `int64` and seeks to next data. A`TypeError` exception
would be thrown when failed.
### PickleIterator.readUInt64()
Returns current value as `uint64` and seeks to next data. A`TypeError` exception
would be thrown when failed.
### PickleIterator.readFloat()
Returns current value as `float` and seeks to next data. A`TypeError` exception
would be thrown when failed.
### PickleIterator.readDouble()
Returns current value as `double` and seeks to next data. A`TypeError` exception
would be thrown when failed.
### PickleIterator.readString()
Returns current value as `String` and seeks to next data. A`TypeError` exception
would be thrown when failed.
|