npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sane-wasm

v0.3.2

Published

A project to bring the SANE API to the web.

Downloads

325

Readme

SANE WebAssembly (sane-wasm)

A project to bring the SANE API to Node.js and the Web using WebAssembly.

It supports USB scanners on browser environments through the WebUSB API and on Node.js using node-usb.

This works by compiling all SANE backends (and required dependencies) to WebAssembly using Emscripten. The other key piece is @RReverser's bridge from libusb to WebUSB (article/article/code/code) for direct USB access.

Right now, it includes all backends that have support for at least one USB device (genesys is not included due to issues). No external backends are included at the moment.

WebScan

Check webscan.goncalomb.com for a demo of sane-wasm. This is a React application that uses sane-wasm for document/image scanning directly in the browser. It exposes all scanning options to the user for full control.

Usage

The pre-compiled WebAssembly package for sane-wasm is published on NPM:

https://www.npmjs.com/package/sane-wasm?activeTab=code

For Web Environments (e.g. Webpack)

npm install -D sane-wasm

The main .js will not be bundled with your application. A loader (lib/loader.js) is provided to automatically load the .js/.wasm files from a CDN (jsdelivr.com). You can configure the loader to serve the files from your server if you want.

See examples/webpack/ for a working example.

For Node.js

npm install sane-wasm usb

The usb package (node-usb) is required to provide USB functionality.

See examples/node/ for a working example.

As Git Submodule (not recommended) / Custom Build

As an alternative, you can add sane-wasm as a submodule to your application and integrate ./build.sh with your build process. This is not recommended as it relies on some magical/dubious code on ./build.sh to make the build work.

You can also just build sane-wasm independently and use the build artifacts...

<script src="build/libsane.js"></script>
<script>
    window.LibSANE().then(lib => {
        // your code
        console.log(lib.sane_init());
    });
</script>
const { libsane } = require('./sane-wasm');
libsane().then(lib => {
    console.log(lib.sane_init());
});
import { libsane } from './sane-wasm';
const lib = await libsane();
console.log(lib.sane_init());

Building

SANE Only

Building requires emscripten and all the required tools to build the dependencies.

The preferred way is just to use the pre-configured Docker image:

git clone --recurse-submodules https://github.com/goncalomb/sane-wasm.git
cd sane-wasm
./build.sh --with-docker --clean

Start the test server with:

./build.sh --with-docker --no-build --emrun

Check the test page at: http://localhost:6931/libsane.html.

build.sh

The ./build.sh script has other options for debugging:

usage: build.sh [options]
  --with-docker  run with docker (preferred)
  --clean        clean 'deps' and 'build' directories
  --no-build     don't actually build
  --debug        enable debug flags
  --emrun        run emrun development server
  --shell        run debug shell (depends on --with-docker)

Full Build (SANE + TypeScript)

To do a full build use npm run build.

API

Most of the SANE API is exposed as-is. Check the SANE Standard.

Some safeguards are in place to avoid API misuse and prevent memory leaks. It's important to understand the SANE API and follow the Code Flow to avoid issues.

Differences with the SANE API

The most important difference with the underlying SANE API is that device handles are not exposed. This means that sane_open() does not return a device handle. A single handle is managed by the internal code. This effectively means that only one device can be accessed at a time. This was a design decision made to simplify the API and prevent other issues.

Personally, I believe that this is an acceptable change, especially for WebAssembly where it may be easier to lose track of opened resources and crash the application. The SANE API is also somewhat unforgiving and building more safeguards around it (especially with multiple handles) is not worth the effort. Ultimately I don't see a use that requires more than one device open at a time. -goncalomb

Documentation

Check API documentation at: goncalomb.github.io/sane-wasm/modules.html.

License

Because of the weird state of SANE's licensing (GPL + linking exception, on some backends), see backends/LICENSE. I'm releasing this project with dual licensing GNU GPLv2 + GNU LGPLv2.1. IANAL, you choose.