How albert-einshutoin/lazy-image works
lazy-image is a Node.js image-optimization product backed by a Rust/N-API engine. Its main workflow accepts a file or buffer, queues transformations and safety policies, then decodes, processes, and encodes on demand to a buffer or file. A separate compiler workflow produces a verified responsive artifact set and manifest in a local directory; the streaming API stages input and output through temporary files. The README also documents browser/Edge upload preflight through a separate Wasm package. Source excerpts are partial, so uncertain internal wiring is omitted.
Main entry points: engine.rs ImageEngine API · artifact-compiler.js Artifact Compiler · index.js JS Package API · output_ops.rs Output Methods
Components 25
Node Interfaces
- JS Package API
index.js - Compile CLI
bin/lazy-image.js - Streaming API
streaming/pipeline.js
Artifact Compiler
- Artifact Compiler
lib/artifact-compiler.js - Artifact Policy
lib/artifact-policy.js - Compiler Helpers
lib/helpers.js
Image Engine
- Native Binding
index.js - ImageEngine API
src/engine/api/engine.rs - Queued Operations
src/engine/api/pipeline_ops.rs - Output Methods
src/engine/api/output_ops.rs - Batch Operations
src/engine/api/batch_ops.rs - Header Inspection
src/inspect.rs
Processing Internals
- Image Sources
src/engine/io/source.rs - Input Firewall
src/engine/firewall.rs - Image Decoder
src/engine/decoder.rs - Operation Pipeline
src/engine/pipeline/apply.rs - Image Encoder
src/engine/encoder.rs - Metadata Handling
src/engine/metadata.rs - Metadata I/O
src/engine/io/mod.rs
Wasm Preflight
- Browser Optimizer
packages/lazy-image-wasm/browser.js - Wasm Runtime
packages/lazy-image-wasm/shared.js - Worker Handler
packages/lazy-image-wasm/worker.js
Other components
- Node.js Caller
- CLI User
- Local Filesystem
Connections 30
- Node.js Caller → JS Package API: calls
- CLI User → Compile CLI: runs
- JS Package API → Native Binding: loads binding
- JS Package API → Artifact Compiler: exports compiler
- JS Package API → Header Inspection: exports inspect
- JS Package API → Streaming API: exports streaming
- Compile CLI → Artifact Compiler: compiles artifacts
- Artifact Compiler → Artifact Policy: applies policy
- Artifact Compiler → Compiler Helpers: uses helpers
- Artifact Compiler → Native Binding: optimizes images
- Artifact Compiler → Local Filesystem: stages and commits
- Streaming API → Local Filesystem: stages files
- Streaming API → Native Binding: processes image
- Native Binding → ImageEngine API: dispatches calls
- ImageEngine API → Image Sources: creates source
- ImageEngine API → Queued Operations: queues operations
- ImageEngine API → Output Methods: dispatches output
- ImageEngine API → Batch Operations: dispatches batches
- ImageEngine API → Input Firewall: configures policy
- Output Methods → Image Decoder: decodes input
- Output Methods → Operation Pipeline: applies operations
- Output Methods → Image Encoder: encodes output
- Image Decoder → Image Sources: reads source
- Image Decoder → Input Firewall: checks input
- Operation Pipeline → Image Encoder: produces pixels
- Output Methods → Metadata Handling: applies policy
- Metadata Handling → Metadata I/O: reads and embeds
- Node.js Caller → Browser Optimizer: preflights upload
- Worker Handler → Browser Optimizer: calls optimizer
- Worker Handler → Wasm Runtime: formats errors