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

How to serve the .wasm from a local file instead of a CDN, for offline use. #95

Closed
carafelix opened this issue Apr 22, 2024 · 2 comments

Comments

@carafelix
Copy link

carafelix commented Apr 22, 2024

It is possible to instruct setZXingModuleOverrides to locate the .wasm in a local directory? like returning ./src/to/.wasm/ ??

@Sec-ant
Copy link
Owner

Sec-ant commented Apr 23, 2024

Not sure what your use case and runtime would be, but here's a small demo to use it locally in node.

File structure:

.
├── index.js
├── node_modules
├── package-lock.json
├── package.json
└── zxing_reader.wasm

index.js:

import {
  setZXingModuleOverrides,
  readBarcodesFromImageFile,
} from "zxing-wasm/reader";

import { readFileSync } from "node:fs";
import { fileURLToPath } from "node:url";

setZXingModuleOverrides({
  wasmBinary: readFileSync(
    fileURLToPath(new URL("./zxing_reader.wasm", import.meta.url)),
  ),
});

fetch(
  "https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=Hello%20world!",
)
  .then((resp) => resp.blob())
  .then(readBarcodesFromImageFile)
  .then(console.log);

@Sec-ant Sec-ant closed this as not planned Won't fix, can't repro, duplicate, stale May 7, 2024
@Sec-ant Sec-ant pinned this issue May 7, 2024
@gfeller
Copy link

gfeller commented Jun 19, 2024

My solution:

setZXingModuleOverrides({
  locateFile : () => {
    return  "/assets/libs/zxing/zxing_full.wasm";
  }
});

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

No branches or pull requests

3 participants