{"_id":"@bun-win32/winusb","_rev":"3-a826c3ccea199e3d96d352cdb9b11a9b","name":"@bun-win32/winusb","dist-tags":{"latest":"2.0.1"},"versions":{"1.0.0":{"name":"@bun-win32/winusb","version":"1.0.0","keywords":["bun","ffi","win32","windows","winusb","usb","bindings","typescript","dll"],"author":"Stev Peifer <stev@bell.net>","license":"MIT","_id":"@bun-win32/winusb@1.0.0","maintainers":[{"name":"obscuritysrl","email":"stev@bell.net"}],"homepage":"https://github.com/ObscuritySRL/bun-win32#readme","bugs":{"url":"https://github.com/ObscuritySRL/bun-win32/issues"},"dist":{"shasum":"014b4b99c5ed126c9660b886faac8593c830c6e4","tarball":"https://registry.npmjs.org/@bun-win32/winusb/-/winusb-1.0.0.tgz","fileCount":6,"integrity":"sha512-zsatDX5Cv7AcgsoLAT7Ih7rmZqG0iA4+fnxZaRamoDagkU1StSyPIrWqk3fhNgT2eyClnm383QTmIF0jP9uxag==","signatures":[{"sig":"MEQCIGHTikFHuMPGHiW8StE64CHrKkfxmR+yRzg5Tevpoht0AiAjDDQH5sHpBDgg4TzrlJJDPC5U7S/lsTVeRvEss73maA==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":27040},"main":"./index.ts","type":"module","module":"index.ts","shasum":"014b4b99c5ed126c9660b886faac8593c830c6e4","engines":{"bun":">=1.1.0"},"exports":{".":"./index.ts"},"private":false,"scripts":{"example:usb-device-inspector":"bun ./example/usb-device-inspector.ts","example:descriptor-visualizer":"bun ./example/descriptor-visualizer.ts"},"_npmUser":{"name":"obscuritysrl","email":"stev@bell.net"},"_integrity":"sha512-zsatDX5Cv7AcgsoLAT7Ih7rmZqG0iA4+fnxZaRamoDagkU1StSyPIrWqk3fhNgT2eyClnm383QTmIF0jP9uxag==","repository":{"url":"git://github.com/ObscuritySRL/bun-win32.git","type":"git","directory":"packages/winusb"},"_npmVersion":"10.8.3","description":"Zero-dependency, zero-overhead Win32 WINUSB bindings for Bun (FFI) on Windows.","directories":{},"sideEffects":false,"_nodeVersion":"24.3.0","dependencies":{"@bun-win32/core":"1.1.2"},"_hasShrinkwrap":false,"devDependencies":{"@types/bun":"latest","@bun-win32/kernel32":"1.0.21"},"peerDependencies":{"typescript":"^5"},"_npmOperationalInternal":{"tmp":"tmp/winusb_1.0.0_1775741909061_0.858689948770984","host":"s3://npm-registry-packages-npm-production"}},"2.0.0":{"name":"@bun-win32/winusb","version":"2.0.0","keywords":["bun","ffi","win32","windows","winusb","usb","bindings","typescript","dll"],"author":"Stev Peifer <stev.p@outlook.com>","license":"MIT","_id":"@bun-win32/winusb@2.0.0","maintainers":[{"name":"obscuritysrl","email":"stev.p@outlook.com"}],"homepage":"https://github.com/ObscuritySRL/bun-win32#readme","bugs":{"url":"https://github.com/ObscuritySRL/bun-win32/issues"},"dist":{"shasum":"d979648428133ecfb47fc7a5ef8660a37012d9a8","tarball":"https://registry.npmjs.org/@bun-win32/winusb/-/winusb-2.0.0.tgz","fileCount":6,"integrity":"sha512-iWoEX9aRc+FWQPP943mXJuY4wbIavndQxjkcN/sXma8ghpBhdgCS8efnAMv4/dbcGv/FimDpyVQ1jsddMXCNjQ==","signatures":[{"sig":"MEUCIBhe/NuAc1yf5SGMauMvcoqSd1yZR+S1yqeuGH2p3xXmAiEAguHyeyE6zNwGqdTu49Z6H+uVGLHUpWuvs/WYIAKg7Us=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":28805},"main":"./index.ts","type":"module","module":"index.ts","shasum":"d979648428133ecfb47fc7a5ef8660a37012d9a8","engines":{"bun":">=1.1.0"},"exports":{".":"./index.ts"},"private":false,"scripts":{"example:usb-device-inspector":"bun ./example/usb-device-inspector.ts","example:descriptor-visualizer":"bun ./example/descriptor-visualizer.ts"},"_npmUser":{"name":"obscuritysrl","email":"stev.p@outlook.com"},"_integrity":"sha512-iWoEX9aRc+FWQPP943mXJuY4wbIavndQxjkcN/sXma8ghpBhdgCS8efnAMv4/dbcGv/FimDpyVQ1jsddMXCNjQ==","repository":{"url":"git://github.com/ObscuritySRL/bun-win32.git","type":"git","directory":"packages/winusb"},"_npmVersion":"10.8.3","description":"Zero-dependency, zero-overhead Win32 WINUSB bindings for Bun (FFI) on Windows.","directories":{},"sideEffects":false,"_nodeVersion":"26.3.0","dependencies":{"@bun-win32/core":"2.0.0"},"_hasShrinkwrap":false,"devDependencies":{"@types/bun":"latest","@bun-win32/kernel32":"2.0.0"},"peerDependencies":{"typescript":"^5"},"_npmOperationalInternal":{"tmp":"tmp/winusb_2.0.0_1782436000951_0.9316222500919316","host":"s3://npm-registry-packages-npm-production"}},"2.0.1":{"author":"Stev Peifer <stev.p@outlook.com>","bugs":{"url":"https://github.com/ObscuritySRL/bun-win32/issues"},"dependencies":{"@bun-win32/core":"2.0.1"},"description":"Zero-dependency, zero-overhead Win32 WINUSB bindings for Bun (FFI) on Windows.","devDependencies":{"@bun-win32/kernel32":"2.0.1","@types/bun":"latest"},"exports":{".":"./index.ts"},"license":"MIT","module":"index.ts","name":"@bun-win32/winusb","peerDependencies":{"typescript":"^5"},"private":false,"homepage":"https://github.com/ObscuritySRL/bun-win32#readme","repository":{"type":"git","url":"git://github.com/ObscuritySRL/bun-win32.git","directory":"packages/winusb"},"type":"module","version":"2.0.1","main":"./index.ts","keywords":["bun","ffi","win32","windows","winusb","usb","bindings","typescript","dll"],"sideEffects":false,"engines":{"bun":">=1.1.0"},"scripts":{"example:descriptor-visualizer":"bun ./example/descriptor-visualizer.ts","example:usb-device-inspector":"bun ./example/usb-device-inspector.ts"},"_id":"@bun-win32/winusb@2.0.1","_integrity":"sha512-9O9JXupIek4Rn6B3VJcOtQ5PgwveIblNpr51eqV5nDCk/h19s7euMyuWJWG+iOphGCnmqViGc01WQtZa25jdAw==","_nodeVersion":"26.3.0","_npmVersion":"10.8.3","shasum":"3ee9a880112a7800cfad602b161e6821672880c0","dist":{"integrity":"sha512-9O9JXupIek4Rn6B3VJcOtQ5PgwveIblNpr51eqV5nDCk/h19s7euMyuWJWG+iOphGCnmqViGc01WQtZa25jdAw==","shasum":"3ee9a880112a7800cfad602b161e6821672880c0","tarball":"https://registry.npmjs.org/@bun-win32/winusb/-/winusb-2.0.1.tgz","fileCount":6,"unpackedSize":28805,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQC5KYsIIsEeLpewxiLWGQTcNqZ2u/QVRGkpUoQ96x11DwIhAJc+dgjsaQYFTglfj/xaytdZQ4cUmCCakUgLmYpCeE/P"}]},"_npmUser":{"name":"obscuritysrl","email":"stev.p@outlook.com"},"directories":{},"maintainers":[{"name":"obscuritysrl","email":"stev.p@outlook.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/winusb_2.0.1_1782438225889_0.40769102414166336"},"_hasShrinkwrap":false}},"time":{"created":"2026-04-09T13:38:28.996Z","modified":"2026-06-26T01:43:46.150Z","1.0.0":"2026-04-09T13:38:29.211Z","2.0.0":"2026-06-26T01:06:41.074Z","2.0.1":"2026-06-26T01:43:46.034Z"},"bugs":{"url":"https://github.com/ObscuritySRL/bun-win32/issues"},"author":"Stev Peifer <stev.p@outlook.com>","license":"MIT","homepage":"https://github.com/ObscuritySRL/bun-win32#readme","keywords":["bun","ffi","win32","windows","winusb","usb","bindings","typescript","dll"],"repository":{"type":"git","url":"git://github.com/ObscuritySRL/bun-win32.git","directory":"packages/winusb"},"description":"Zero-dependency, zero-overhead Win32 WINUSB bindings for Bun (FFI) on Windows.","maintainers":[{"name":"obscuritysrl","email":"stev.p@outlook.com"}],"readme":"# @bun-win32/winusb\r\n\r\nZero-dependency, zero-overhead Win32 WinUSB bindings for [Bun](https://bun.sh) on Windows.\r\n\r\n## Overview\r\n\r\n`@bun-win32/winusb` exposes the public `winusb.dll` API using [Bun](https://bun.sh)'s FFI. It provides a single class, `WinUsb`, which lazily binds native symbols on first use. You can optionally preload a subset or all symbols up-front via `Preload()`.\r\n\r\nThe bindings are strongly typed for a smooth DX in TypeScript.\r\n\r\n## Features\r\n\r\n- [Bun](https://bun.sh)-first ergonomics on Windows 10/11.\r\n- Direct FFI to `winusb.dll` (USB device I/O, control transfers, pipe management, isochronous transfers, and more).\r\n- In-source docs in `structs/WinUsb.ts` with links to Microsoft Docs.\r\n- Lazy binding on first call; optional eager preload (`WinUsb.Preload()`).\r\n- No wrapper overhead; calls map 1:1 to native APIs.\r\n- Strongly-typed Win32 aliases (see `types/WinUsb.ts`).\r\n\r\n## Requirements\r\n\r\n- [Bun](https://bun.sh) runtime\r\n- Windows 10 or later\r\n\r\n## Installation\r\n\r\n```sh\r\nbun add @bun-win32/winusb\r\n```\r\n\r\n## Quick Start\r\n\r\n```ts\r\nimport Kernel32, {\r\n  FileAccess,\r\n  FileCreationDisposition,\r\n  FileShareMode,\r\n  INVALID_HANDLE_VALUE,\r\n} from '@bun-win32/kernel32';\r\nimport WinUsb, { DeviceInformationType } from '@bun-win32/winusb';\r\n\r\n// Open a WinUSB device (path from SetupAPI device enumeration)\r\nconst devicePath = Buffer.from('\\\\\\\\.\\\\USB#VID_XXXX&PID_XXXX#...\\\\{GUID}\\0', 'utf16le');\r\nconst deviceHandle = Kernel32.CreateFileW(\r\n  devicePath.ptr,\r\n  FileAccess.GENERIC_READ | FileAccess.GENERIC_WRITE,\r\n  FileShareMode.FILE_SHARE_READ | FileShareMode.FILE_SHARE_WRITE,\r\n  null!,\r\n  FileCreationDisposition.OPEN_EXISTING,\r\n  0,\r\n  0n,\r\n);\r\n\r\nif (deviceHandle === INVALID_HANDLE_VALUE) {\r\n  throw new Error(`CreateFileW failed: ${Kernel32.GetLastError()}`);\r\n}\r\n\r\n// Initialize WinUSB on the device\r\nconst handleBuf = Buffer.alloc(8);\r\nif (WinUsb.WinUsb_Initialize(deviceHandle, handleBuf.ptr)) {\r\n  const interfaceHandle = handleBuf.readBigUInt64LE(0);\r\n\r\n  // Query device speed\r\n  const speedBuf = Buffer.alloc(1);\r\n  const lenBuf = Buffer.alloc(4);\r\n  lenBuf.writeUInt32LE(1, 0);\r\n  WinUsb.WinUsb_QueryDeviceInformation(interfaceHandle, DeviceInformationType.DEVICE_SPEED, lenBuf.ptr, speedBuf.ptr);\r\n  console.log('Device speed:', speedBuf.readUInt8(0));\r\n\r\n  WinUsb.WinUsb_Free(interfaceHandle);\r\n}\r\nKernel32.CloseHandle(deviceHandle);\r\n```\r\n\r\n> [!NOTE]\r\n> AI agents: see `AI.md` for the package binding contract and source-navigation guidance. It explains how to use the package without scanning the entire implementation.\r\n\r\n## Examples\r\n\r\nRun the included examples:\r\n\r\n```sh\r\nbun run example:descriptor-visualizer\r\nbun run example:usb-device-inspector\r\n```\r\n\r\n## Notes\r\n\r\n- Either rely on lazy binding or call `WinUsb.Preload()`.\r\n- Windows only. Bun runtime required.\n- **SAL types & naming:** nullability is in the **type** — `Optional<T>` (formally optional, SAL `_*opt_`) and `Nullable<T>` (plain `[in]`/`[out]` the docs say can be NULL), the null sentinel derived from `T` (`null` for pointers `LP*`/`P*`, `0n` for handles/by-value addresses); direction is in the **parameter name** — `_out` (`_Out_`), `_in_out` (`_Inout_`), `_In_` bare. See `AI.md` and the repo `AGENTS.md`.\n","readmeFilename":"README.md"}