星油企业版

This commit is contained in:
caolc
2022-08-08 09:17:43 +08:00
commit e3238cb907
517 changed files with 80472 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
const utils = require('./utils')
console.log('hello worker')
worker.postMessage({
msg: 'hello from worker: ' + utils.test(),
buffer: utils.str2ab('hello arrayBuffer from worker')
})
worker.onMessage((msg) => {
console.log('[Worker] on appservice message', msg)
const buffer = msg.buffer
console.log('[Worker] on appservice buffer length ', buffer)
console.log('[Worker] on appservice buffer', utils.ab2str(buffer))
})

View File

@@ -0,0 +1,22 @@
function test() {
return 1 + 1
}
function ab2str(buf) {
return String.fromCharCode.apply(null, new Uint16Array(buf));
}
function str2ab(str) {
var buf = new ArrayBuffer(str.length * 2); // 2 bytes for each char
var bufView = new Uint16Array(buf);
for (var i = 0, strLen = str.length; i < strLen; i++) {
bufView[i] = str.charCodeAt(i);
}
return buf;
}
module.exports = {
test: test,
ab2str: ab2str,
str2ab: str2ab
}