-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample.js
More file actions
30 lines (24 loc) · 745 Bytes
/
sample.js
File metadata and controls
30 lines (24 loc) · 745 Bytes
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
var sample = require('./build/Release/sample.node');
function PrintJS(arrayBuffer) {
var buffer = new Buffer(new Uint8Array(arrayBuffer));
try {
if (Buffer.byteLength(buffer, 'utf8')) {
console.log('JS:', "'" + buffer.toString('utf8') + "'", Buffer.byteLength(buffer, 'utf8'));
}
} catch(ignored) {
console.log('JS:', buffer.toString('utf8'));
}
}
function Print(arrayBuffer) {
sample.PrintArrayBuffer(arrayBuffer);
PrintJS(arrayBuffer);
}
var buf = new Buffer(5);
buf.write('HELLO', 0);
var arrayBuffer = new Uint8Array(buf).buffer;
for (var index = 0; index < 100; index++) {
Print(arrayBuffer);
Print('New ArrayBuffer From String!');
Print(sample.CreateArrayBuffer());
sample.DisposeMemory();
}