1. Stability Consideration
Deno has recently introduced support for raw binary imports under the --unstable-raw-imports flag. While this is a welcome step forward, it is recommended that the feature remain unstable for the time being. This would allow the community to evaluate its ergonomics and performance characteristics, while also providing time to align with the upcoming Immutable ArrayBuffer proposal currently under consideration by TC39.
2. Import Type Naming
The current use of type: "bytes" for binary imports could be refined for clarity and semantic precision. I propose renaming it to:
import data from "./file.bin" with { type: "octet" };
- The term "octet" is consistent with established terminology in networking and MIME types (e.g.,
application/octet-stream). - It avoids confusion with higher-level abstractions like
Uint8Array, reinforcing that the import represents raw binary data.
3. Return Type: ArrayBuffer vs. Uint8Array
Rather than returning a Uint8Array, the import should yield an ArrayBuffer directly. This approach offers several advantages:
Uint8Arrayis a view over binary data, not the data itself. Returning anArrayBuffermakes the semantics of the import more explicit.- It encourages developers to consciously select the appropriate view (e.g.,
DataView,Uint16Array) based on their specific needs. - This design aligns with APIs like the Web Crypto API, which also favor
ArrayBufferfor safety and clarity.