Registry / ai-ml / zbar.wasm

zbar.wasm

JSON →
library2.1.1jsnpmunverified

A WebAssembly build of the C/C++ ZBar barcode scanning library, providing fast and portable barcode recognition (including QRCode, EAN13, CODE128, etc.) for browsers and Node.js. Current stable version is 2.1.1. Released irregularly, maintained on GitHub. Key differentiator: leverages native ZBar performance via WebAssembly, offering a simple JavaScript API for scanning barcodes from ImageData.

npm install zbar.wasm
INSTALL
IMPORT
SIG · ZBAR.WASM
Z
zbar.wasm
ai-mljavascriptv2.1.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

scanImageData
✓ import { scanImageData } from 'zbar.wasm'
✗ const scanImageData = require('zbar.wasm').scanImageData
ESM import recommended; CommonJS require works but may not resolve .wasm file correctly in bundlers
default
✓ import zbar from 'zbar.wasm'
✗ import * as zbar from 'zbar.wasm'
Default export is not documented; use named exports like scanImageData instead
Scanner
✓ import { Scanner } from 'zbar.wasm'
Scanner class for advanced usage; available since v2.0.0

Scans a barcode from an image URL using Node.js canvas and prints type and decoded data.

const { createCanvas, loadImage } = require('canvas'); const { scanImageData } = require('zbar.wasm'); const getImageData = async (src) => { const img = await loadImage(src); const canvas = createCanvas(img.width, img.height); const ctx = canvas.getContext('2d'); ctx.drawImage(img, 0, 0); return ctx.getImageData(0, 0, img.width, img.height); }; const url = 'https://raw.githubusercontent.com/zbar-wasm/demo/master/node/test.png'; const main = async () => { const img = await getImageData(url); const res = await scanImageData(img); console.log(res[0].typeName); console.log(res[0].decode()); }; main().catch(console.error);
Debug
Known issues
gotchaWebpack requires file-loader for .wasm file (zbar.wasm.bin) - do not use default wasm extension handling
fix
Add rule for zbar.wasm.bin: { test: /\.bin$/, use: 'file-loader' }
affects: >=0.0.0
gotchaBrowser environment needs to load the .wasm file asynchronously; ensure MIME type is correct on server (application/wasm)
fix
Serve .wasm files with Content-Type: application/wasm
affects: >=0.0.0
breakingVersion 2.0.0 changed the API from default export to named exports
fix
Replace import zbar from 'zbar.wasm' with import { scanImageData } from 'zbar.wasm'
affects: <2.0.0
Errors
Common errors & fixes
Module not found: Error: Can't resolve 'zbar.wasm.bin'
Webpack not configured to handle .bin file extension
fix
Add file-loader rule for /zbar\.wasm\.bin$/ in webpack config
TypeError: Failed to fetch dynamically imported module
Browser can't load .wasm file due to MIME type mismatch
fix
Ensure server sends application/wasm for .wasm files
Upgrade
Version history
2.1.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
46 hits · last 30 days
node
40
OpenAI (training)
1
Resources
zbar.wasm — npm install zbar.wasm · libregistry