1# DataView
2
3Class `Napi::DataView` inherits from class [`Napi::Object`][].
4
5The `Napi::DataView` class corresponds to the
6[JavaScript `DataView`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView)
7class.
8
9## Methods
10
11### New
12
13Allocates a new `Napi::DataView` instance with a given `Napi::ArrayBuffer`.
14
15```cpp
16static Napi::DataView Napi::DataView::New(napi_env env, Napi::ArrayBuffer arrayBuffer);
17```
18
19- `[in] env`: The environment in which to create the `Napi::DataView` instance.
20- `[in] arrayBuffer` : `Napi::ArrayBuffer` underlying the `Napi::DataView`.
21
22Returns a new `Napi::DataView` instance.
23
24### New
25
26Allocates a new `Napi::DataView` instance with a given `Napi::ArrayBuffer`.
27
28```cpp
29static Napi::DataView Napi::DataView::New(napi_env env, Napi::ArrayBuffer arrayBuffer, size_t byteOffset);
30```
31
32- `[in] env`: The environment in which to create the `Napi::DataView` instance.
33- `[in] arrayBuffer` : `Napi::ArrayBuffer` underlying the `Napi::DataView`.
34- `[in] byteOffset` : The byte offset within the `Napi::ArrayBuffer` from which to start projecting the `Napi::DataView`.
35
36Returns a new `Napi::DataView` instance.
37
38### New
39
40Allocates a new `Napi::DataView` instance with a given `Napi::ArrayBuffer`.
41
42```cpp
43static Napi::DataView Napi::DataView::New(napi_env env, Napi::ArrayBuffer arrayBuffer, size_t byteOffset, size_t byteLength);
44```
45
46- `[in] env`: The environment in which to create the `Napi::DataView` instance.
47- `[in] arrayBuffer` : `Napi::ArrayBuffer` underlying the `Napi::DataView`.
48- `[in] byteOffset` : The byte offset within the `Napi::ArrayBuffer` from which to start projecting the `Napi::DataView`.
49- `[in] byteLength` : Number of elements in the `Napi::DataView`.
50
51Returns a new `Napi::DataView` instance.
52
53### Constructor
54
55Initializes an empty instance of the `Napi::DataView` class.
56
57```cpp
58Napi::DataView();
59```
60
61### Constructor
62
63Initializes a wrapper instance of an existing `Napi::DataView` instance.
64
65```cpp
66Napi::DataView(napi_env env, napi_value value);
67```
68
69- `[in] env`: The environment in which to create the `Napi::DataView` instance.
70- `[in] value`: The `Napi::DataView` reference to wrap.
71
72### ArrayBuffer
73
74```cpp
75Napi::ArrayBuffer Napi::DataView::ArrayBuffer() const;
76```
77
78Returns the backing array buffer.
79
80### ByteOffset
81
82```cpp
83size_t Napi::DataView::ByteOffset() const;
84```
85
86Returns the offset into the `Napi::DataView` where the array starts, in bytes.
87
88### ByteLength
89
90```cpp
91size_t Napi::DataView::ByteLength() const;
92```
93
94Returns the length of the array, in bytes.
95
96### GetFloat32
97
98```cpp
99float Napi::DataView::GetFloat32(size_t byteOffset) const;
100```
101
102- `[in] byteOffset`: The offset, in byte, from the start of the view where to read the data.
103
104Returns a signed 32-bit float (float) at the specified byte offset from the start of the `Napi::DataView`.
105
106### GetFloat64
107
108```cpp
109double Napi::DataView::GetFloat64(size_t byteOffset) const;
110```
111
112- `[in] byteOffset`: The offset, in byte, from the start of the view where to read the data.
113
114Returns a signed 64-bit float (double) at the specified byte offset from the start of the `Napi::DataView`.
115
116### GetInt8
117
118```cpp
119int8_t Napi::DataView::GetInt8(size_t byteOffset) const;
120```
121
122- `[in] byteOffset`: The offset, in byte, from the start of the view where to read the data.
123
124Returns a signed 8-bit integer (byte) at the specified byte offset from the start of the `Napi::DataView`.
125
126### GetInt16
127
128```cpp
129int16_t Napi::DataView::GetInt16(size_t byteOffset) const;
130```
131
132- `[in] byteOffset`: The offset, in byte, from the start of the view where to read the data.
133
134Returns a signed 16-bit integer (short) at the specified byte offset from the start of the `Napi::DataView`.
135
136### GetInt32
137
138```cpp
139int32_t Napi::DataView::GetInt32(size_t byteOffset) const;
140```
141
142- `[in] byteOffset`: The offset, in byte, from the start of the view where to read the data.
143
144Returns a signed 32-bit integer (long) at the specified byte offset from the start of the `Napi::DataView`.
145
146### GetUint8
147
148```cpp
149uint8_t Napi::DataView::GetUint8(size_t byteOffset) const;
150```
151
152- `[in] byteOffset`: The offset, in byte, from the start of the view where to read the data.
153
154Returns a unsigned 8-bit integer (unsigned byte) at the specified byte offset from the start of the `Napi::DataView`.
155
156### GetUint16
157
158```cpp
159uint16_t Napi::DataView::GetUint16(size_t byteOffset) const;
160```
161
162- `[in] byteOffset`: The offset, in byte, from the start of the view where to read the data.
163
164Returns a unsigned 16-bit integer (unsigned short) at the specified byte offset from the start of the `Napi::DataView`.
165
166### GetUint32
167
168```cpp
169uint32_t Napi::DataView::GetUint32(size_t byteOffset) const;
170```
171
172- `[in] byteOffset`: The offset, in byte, from the start of the view where to read the data.
173
174Returns a unsigned 32-bit integer (unsigned long) at the specified byte offset from the start of the `Napi::DataView`.
175
176### SetFloat32
177
178```cpp
179void Napi::DataView::SetFloat32(size_t byteOffset, float value) const;
180```
181
182- `[in] byteOffset`: The offset, in byte, from the start of the view where to read the data.
183- `[in] value`: The value to set.
184
185### SetFloat64
186
187```cpp
188void Napi::DataView::SetFloat64(size_t byteOffset, double value) const;
189```
190
191- `[in] byteOffset`: The offset, in byte, from the start of the view where to read the data.
192- `[in] value`: The value to set.
193
194### SetInt8
195
196```cpp
197void Napi::DataView::SetInt8(size_t byteOffset, int8_t value) const;
198```
199
200- `[in] byteOffset`: The offset, in byte, from the start of the view where to read the data.
201- `[in] value`: The value to set.
202
203### SetInt16
204
205```cpp
206void Napi::DataView::SetInt16(size_t byteOffset, int16_t value) const;
207```
208
209- `[in] byteOffset`: The offset, in byte, from the start of the view where to read the data.
210- `[in] value`: The value to set.
211
212### SetInt32
213
214```cpp
215void Napi::DataView::SetInt32(size_t byteOffset, int32_t value) const;
216```
217
218- `[in] byteOffset`: The offset, in byte, from the start of the view where to read the data.
219- `[in] value`: The value to set.
220
221### SetUint8
222
223```cpp
224void Napi::DataView::SetUint8(size_t byteOffset, uint8_t value) const;
225```
226
227- `[in] byteOffset`: The offset, in byte, from the start of the view where to read the data.
228- `[in] value`: The value to set.
229
230### SetUint16
231
232```cpp
233void Napi::DataView::SetUint16(size_t byteOffset, uint16_t value) const;
234```
235
236- `[in] byteOffset`: The offset, in byte, from the start of the view where to read the data.
237- `[in] value`: The value to set.
238
239### SetUint32
240
241```cpp
242void Napi::DataView::SetUint32(size_t byteOffset, uint32_t value) const;
243```
244
245- `[in] byteOffset`: The offset, in byte, from the start of the view where to read the data.
246- `[in] value`: The value to set.
247
248[`Napi::Object`]: ./object.md
249