mirror of
https://github.com/oven-sh/bun
synced 2026-02-13 04:18:58 +00:00
Adds support for importing binary files as Uint8Array using the ES2022 import attributes syntax:
```javascript
import data from './file.bin' with { type: "bytes" };
// data is a Uint8Array containing the file contents
```
This follows the same pattern as the existing "text" and "file" import types, providing a convenient way to load binary data at build time. The implementation uses base64 encoding during transpilation and converts to Uint8Array at runtime using the native Uint8Array.fromBase64 method when available, with a polyfill fallback.
Key changes:
- Add bytes loader enum value and mappings in options.zig
- Add __base64ToUint8Array runtime helper using Uint8Array.fromBase64
- Implement transpiler support using lazy export AST pattern
- Add bundler support in ParseTask.zig
- Handle bytes loader in ModuleLoader with special case for runtime
- Add comprehensive test coverage
The loader validates that only default imports are allowed, matching the behavior of text and file loaders.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>