Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update deps #99

Merged
merged 1 commit into from
Apr 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions deps.pure_ext.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// @deno-types="https://deno.land/[email protected]/csv/mod.ts"
export {parse, stringify} from "https://esm.sh/gh/denoland/[email protected]/csv/mod.ts?bundle&target=esnext";
// @deno-types="https://deno.land/x/[email protected].40/index.d.ts"
export {ZipReader, ZipWriter, Uint8ArrayReader, Uint8ArrayWriter} from "https://esm.sh/gh/gildas-lormeau/[email protected].40/index.js?bundle&target=esnext";
// @deno-types="https://deno.land/x/[email protected].41/index.d.ts"
export {ZipReader, ZipWriter, Uint8ArrayReader, Uint8ArrayWriter} from "https://esm.sh/gh/gildas-lormeau/[email protected].41/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";
export * as xlsxcp from "https://cdn.sheetjs.com/xlsx-0.20.1/package/dist/cpexcel.full.mjs";
// @deno-types="https://cdn.sheetjs.com/xlsx-0.20.2/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.2/package/xlsx.mjs";
export * as xlsxcp from "https://cdn.sheetjs.com/xlsx-0.20.2/package/dist/cpexcel.full.mjs";
14 changes: 7 additions & 7 deletions src/pure/minipack.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {u8Encode, u8Decode} from "./text.ts";

const sizeName = 1;
const sizeBody = 4;
const MINIPACK_NAME = 1;
const MINIPACK_BODY = 4;

/**
* Simple name and data pair.
Expand All @@ -25,17 +25,17 @@ export interface DataMap{
* ```
*/
export function minipackEncode(files:DataMap[]):Uint8Array{
const archive = new Uint8Array(files.reduce((size, {name, body}) => size + sizeName + sizeBody + u8Encode(name).byteLength + body.byteLength, 0));
const archive = new Uint8Array(files.reduce((size, {name, body}) => size + MINIPACK_NAME + MINIPACK_BODY + u8Encode(name).byteLength + body.byteLength, 0));

let i = 0;
for(const {name, body} of files){
const u8name = u8Encode(name);

new DataView(archive.buffer, i).setUint8(0, u8name.byteLength);
i += sizeName;
i += MINIPACK_NAME;

new DataView(archive.buffer, i).setUint32(0, body.byteLength);
i += sizeBody;
i += MINIPACK_BODY;

archive.set(u8name, i);
i += u8name.byteLength;
Expand Down Expand Up @@ -65,10 +65,10 @@ export function minipackDecode(archive:Uint8Array):DataMap[]{

for(let i = 0; i < archive.byteLength;){
const ns = new DataView(archive.buffer, i).getUint8(0);
i += sizeName;
i += MINIPACK_NAME;

const bs = new DataView(archive.buffer, i).getUint32(0);
i += sizeBody;
i += MINIPACK_BODY;

files.push({
name: u8Decode(archive.subarray(i, i += ns)),
Expand Down
8 changes: 4 additions & 4 deletions src/pure/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {u8Encode} from "./text.ts";

interface TaskMessage<T extends unknown>{
message: T;
transfers?: (Transferable | ArrayBufferView)[];
transfers?: Transferable[];
}

/**
Expand All @@ -14,7 +14,7 @@ export type TaskAction<T extends unknown, K extends unknown> = (message:T) => Ta
/**
* Run registered `TaskAction` in worker thread.
*/
export type TaskContext<T extends unknown, K extends unknown> = (message:T, transfers?:(Transferable | ArrayBufferView)[]) => Promise<K>;
export type TaskContext<T extends unknown, K extends unknown> = (message:T, transfers?:Transferable[]) => Promise<K>;

/**
* Register `TaskAction` and return reusable task execution context.
Expand All @@ -38,7 +38,7 @@ export function createTask<T extends unknown, K extends unknown>(task:TaskAction
globalThis.onmessage = async({data})=>{
const {message, transfers} = await(${task.toString()})(data);
globalThis.postMessage(message, {
transfer: transfers?.map(v => "buffer" in v ? v.buffer : v)
transfer: transfers
});
};
`;
Expand All @@ -65,7 +65,7 @@ export function createTask<T extends unknown, K extends unknown>(task:TaskAction
};

worker.postMessage(message, {
transfer: transfers?.map(v => "buffer" in v ? v.buffer : v)
transfer: transfers
});
});
};
Expand Down
4 changes: 2 additions & 2 deletions test/pure/worker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ Deno.test({

return {
message: result,
transfers: [result]
transfers: [result.buffer]
};
});

const result = await task(sample1, [sample1]);
const result = await task(sample1, [sample1.buffer]);

assertEquals(result, sample2);
}
Expand Down