Skip to content

Commit

Permalink
Code stab (#97)
Browse files Browse the repository at this point in the history
* use already method.

* worker source from BlobURL to DataURL.

* update workflow.

* update deps.
  • Loading branch information
dojyorin authored Mar 22, 2024
1 parent 386c70d commit d561079
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"uses": "actions/checkout@v4"
}, {
"name": "dispatch release",
"uses": "softprops/action-gh-release@v1",
"uses": "softprops/action-gh-release@v2",
"with": {
"generate_release_notes": true
}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ jobs:
- name: clone repository
uses: actions/checkout@v4
- name: dispatch release
uses: softprops/action-gh-release@v1
uses: softprops/action-gh-release@v2
with:
generate_release_notes: true
8 changes: 4 additions & 4 deletions .github/workflows/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
"jobs": {
"test": {
"name": "test: ${{matrix.os}}",
"runs-on": "${{matrix.os}}",
"runs-on": "${{matrix.os}}-latest",
"strategy": {
"fail-fast": true,
"matrix": {
"os": [
"ubuntu-latest",
"macos-latest",
"windows-latest"
"ubuntu",
"macos",
"windows"
]
}
},
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ on:
jobs:
test:
name: 'test: ${{matrix.os}}'
runs-on: ${{matrix.os}}
runs-on: ${{matrix.os}}-latest
strategy:
fail-fast: true
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest
- ubuntu
- macos
- windows
steps:
- name: clone repository
uses: actions/checkout@v4
Expand Down
6 changes: 3 additions & 3 deletions deps.deno_ext.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export {Logger, ConsoleHandler, FileHandler} from "https://deno.land/std@0.215.0/log/mod.ts";
export {format} from "https://deno.land/std@0.215.0/datetime/mod.ts";
export {Logger, ConsoleHandler, FileHandler} from "https://deno.land/std@0.220.1/log/mod.ts";
export {format} from "https://deno.land/std@0.220.1/datetime/mod.ts";

export {type Element, DOMParser} from "https://deno.land/x/deno_dom@v0.1.45/deno-dom-wasm.ts";

// @deno-types="npm:@types/nodemailer@6.4.14"
export {createTransport} from "npm:nodemailer@6.9.9";
export {createTransport} from "npm:nodemailer@6.9.13";
8 changes: 4 additions & 4 deletions deps.pure_ext.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @deno-types="https://deno.land/std@0.215.0/csv/mod.ts"
export {parse, stringify} from "https://esm.sh/gh/denoland/deno_std@0.215.0/csv/mod.ts?bundle&target=esnext";
// @deno-types="https://deno.land/x/zipjs@v2.7.34/index.d.ts"
export {ZipReader, ZipWriter, Uint8ArrayReader, Uint8ArrayWriter} from "https://esm.sh/gh/gildas-lormeau/zip.js@v2.7.34/index.js?bundle&target=esnext";
// @deno-types="https://deno.land/std@0.220.1/csv/mod.ts"
export {parse, stringify} from "https://esm.sh/gh/denoland/deno_std@0.220.1/csv/mod.ts?bundle&target=esnext";
// @deno-types="https://deno.land/x/zipjs@v2.7.40/index.d.ts"
export {ZipReader, ZipWriter, Uint8ArrayReader, Uint8ArrayWriter} from "https://esm.sh/gh/gildas-lormeau/zip.js@v2.7.40/index.js?bundle&target=esnext";

// @deno-types="https://cdn.sheetjs.com/xlsx-0.20.1/package/types/index.d.ts"
export {type WorkBook as RawWorkBook, type WorkSheet as RawWorkSheet, type CellObject as RawWorkCell, set_cptable, read as xlsxRead, write as xlsxWrite, utils as xlsxUtil} from "https://cdn.sheetjs.com/xlsx-0.20.1/package/xlsx.mjs";
Expand Down
8 changes: 4 additions & 4 deletions deps.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export {assertEquals} from "https://deno.land/std@0.215.0/assert/mod.ts";
export {dirname, fromFileUrl} from "https://deno.land/std@0.215.0/path/mod.ts";
export {exists} from "https://deno.land/std@0.215.0/fs/mod.ts";
export {delay} from "https://deno.land/std@0.215.0/async/mod.ts";
export {assertEquals} from "https://deno.land/std@0.220.1/assert/mod.ts";
export {dirname, fromFileUrl} from "https://deno.land/std@0.220.1/path/mod.ts";
export {exists} from "https://deno.land/std@0.220.1/fs/mod.ts";
export {delay} from "https://deno.land/std@0.220.1/async/mod.ts";

export {DOMParser} from "https://deno.land/x/deno_dom@v0.1.45/deno-dom-wasm.ts";

Expand Down
8 changes: 3 additions & 5 deletions src/pure/crypto.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {byteConcat} from "./byte.ts";

/**
* Serialized `CryptoKeyPair`.
*/
Expand Down Expand Up @@ -116,11 +118,7 @@ export async function pkEncrypt(data:Uint8Array, {publicKey, privateKey}:Portabl
iv: generateRandom(12)
};

const output = new Uint8Array(aes.iv.byteLength + data.byteLength + 16);
output.set(aes.iv, 0);
output.set(new Uint8Array(await crypto.subtle.encrypt(aes, await deriveKey({publicKey, privateKey}), data)), aes.iv.byteLength);

return output;
return byteConcat(aes.iv, await crypto.subtle.encrypt(aes, await deriveKey({publicKey, privateKey}), data));
}

/**
Expand Down
22 changes: 9 additions & 13 deletions src/pure/worker.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import {b64DataURL} from "./base64.ts";
import {u8Encode} from "./text.ts";

interface TaskMessage<T extends unknown>{
message: T;
transfers?: (Transferable | ArrayBufferView)[];
Expand Down Expand Up @@ -31,10 +34,9 @@ export type TaskContext<T extends unknown, K extends unknown> = (message:T, tran
* ```
*/
export function createTask<T extends unknown, K extends unknown>(task:TaskAction<T, K>):TaskContext<T, K>{
const script = task.toString();
const regist = /*js*/`
const script = /*js*/`
globalThis.onmessage = async({data})=>{
const {message, transfers} = await(${script})(data);
const {message, transfers} = await(${task.toString()})(data);
globalThis.postMessage(message, {
transfer: transfers?.map(v => "buffer" in v ? v.buffer : v)
});
Expand All @@ -43,29 +45,23 @@ export function createTask<T extends unknown, K extends unknown>(task:TaskAction

return (message, transfers)=>{
return new Promise<K>((res, rej)=>{
const url = URL.createObjectURL(new Blob([regist]));
const worker = new Worker(url, {
const worker = new Worker(b64DataURL(u8Encode(script), "text/javascript"), {
type: "module"
});

function disposeWorker(){
worker.terminate();
URL.revokeObjectURL(url);
}

worker.onmessage = ({data})=>{
res(data);
disposeWorker();
worker.terminate();
};

worker.onerror = (e)=>{
rej(e);
disposeWorker();
worker.terminate();
};

worker.onmessageerror = (e)=>{
rej(e);
disposeWorker();
worker.terminate();
};

worker.postMessage(message, {
Expand Down

0 comments on commit d561079

Please sign in to comment.