Skip to content

js: support constructing a Log from a string - #2

Draft
vicb wants to merge 1 commit into
jbrun3t:devfrom
vicb:vicb/log-from-string
Draft

vicb wants to merge 1 commit into
jbrun3t:devfrom
vicb:vicb/log-from-string

Conversation

@vicb

@vicb vicb commented Aug 27, 2026

Copy link
Copy Markdown

Extends the WASM Log constructor to accept IGC file content as a string in addition to binary buffers (Uint8Array, Buffer, ArrayBuffer).

Key Changes

  1. WASM Bindings (rustigc-wasm/src/lib.rs):

    • Added ContentArg declared via #[wasm_bindgen(typescript_type = "Uint8Array | string")] so TypeScript definitions in rustigc.d.ts reflect constructor(content: Uint8Array | string).
    • Updated Log::new constructor:
  2. Dependencies (rustigc-wasm/Cargo.toml):

    • Added js-sys = "0.3" dependency for typed array inspection and conversion.
  3. Testing (rustigc-wasm/test/wasm.test.js & package.json):

    • Added npm test script to workspace package.json.
    • Added unit tests covering:
      • Log construction from Node.js Buffer.
      • Log construction from Uint8Array and ArrayBuffer.
      • Log construction from IGC string (file fixture and inline text).
      • Error handling on invalid IGC strings and unsupported argument types.

Comment thread rustigc-wasm/src/lib.rs
let val: &JsValue = content.as_ref();
let inner = if let Some(s) = val.as_string() {
rustigc::Log::new(s.as_bytes())
} else if js_sys::ArrayBuffer::is_view(val) || val.is_instance_of::<js_sys::ArrayBuffer>() {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the utils package please

initSync({
module: readFileSync(new URL("../pkg/rustigc_bg.wasm", import.meta.url)),
});

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unit test and utf8 are different topics ... yes I'm splitting terrorist

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you mean that tests should be in a separate commit from the feature they test?

Comment thread rustigc-wasm/Cargo.toml
wasm-bindgen = "0.2"
serde-wasm-bindgen = "0.6"
serde_json = "1"
js-sys = "0.3"

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In utils, and the main binding do not depend on this

@vicb
vicb marked this pull request as draft August 27, 2026 13:43
@jbrun3t
jbrun3t force-pushed the dev branch 3 times, most recently from c8f6b19 to c95abe0 Compare August 28, 2026 20:07
@jbrun3t

jbrun3t commented Aug 28, 2026

Copy link
Copy Markdown
Owner

Added something is that direction in the wasm utils package, let me know if that fits the request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants