Skip to content

Commit

Permalink
fix: do not depend on internal ops (#64)
Browse files Browse the repository at this point in the history
* chore: modernize module

* fmt

---------

Co-authored-by: Dj <[email protected]>
  • Loading branch information
lino-levan and DjDeveloperr authored Mar 3, 2024
1 parent 8f7bb34 commit 5dfb82b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 23 deletions.
1 change: 1 addition & 0 deletions deps.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { decodeBase64, encodeBase64 } from "jsr:@std/[email protected]/base64";
export { dlopen } from "jsr:@denosaurs/[email protected]";
export {
createDownloadURL,
Expand Down
38 changes: 15 additions & 23 deletions src/ffi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -970,30 +970,22 @@ lib.sk_init();

export default lib;

const {
op_ffi_cstr_read,
op_ffi_get_buf,
op_base64_encode,
op_base64_decode,
}: {
op_ffi_cstr_read: (ptr: Deno.PointerValue) => string;
op_ffi_get_buf: (
ptr: Deno.PointerValue,
offset: number,
size: number,
) => ArrayBuffer;
op_base64_encode: (buf: Uint8Array) => string;
op_base64_decode: (base64: string) => Uint8Array;
// deno-lint-ignore no-explicit-any
} = (Deno as any)[(Deno as any).internal].core.ops;

export function cstr(str: string) {
return new TextEncoder().encode(str + "\0");
}

export {
op_base64_decode as decodeBase64,
op_base64_encode as encodeBase64,
op_ffi_cstr_read as readCstr,
op_ffi_get_buf as getBuffer,
};
export function readCstr(ptr: Deno.PointerValue): string {
return new Deno.UnsafePointerView(ptr!).getCString();
}

export function getBuffer(
ptr: Deno.PointerValue,
offset: number,
size: number,
): Uint8Array {
return new Uint8Array(
new Deno.UnsafePointerView(ptr!).getArrayBuffer(size, offset),
);
}

export { decodeBase64, encodeBase64 } from "../deps.ts";

0 comments on commit 5dfb82b

Please sign in to comment.