Skip to content

[GR-74256] Implement Import Bytes Proposal #1015

@woess

Description

@woess

TL;DR

We plan to implement the Import Bytes proposal in GraalJS. It adds support for importing arbitrary binary files as immutable Uint8Array.

Details

Importing raw bytes is a useful and common operation in JavaScript, similar to importing JSON, but applicable to arbitrary files such as images or other binary assets. A standard way to import bytes would make this use case simpler and more portable across JavaScript environments.

Today, developers typically need platform-specific APIs such as fs, fetch(), or other runtime-specific mechanisms to load file contents as bytes. This adds boilerplate and often requires environment detection. The Import Bytes proposal provides a single standard mechanism instead:

import bytes from "./photo.png" with { type: "bytes" };

The imported value is a Uint8Array backed by an immutable ArrayBuffer. This integrates naturally with the existing module system and import attributes, while reducing boilerplate and improving portability for code that needs access to raw file contents.

Metadata

Metadata

Assignees

Labels

proposalECMAScript Proposals

Type

No type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions