Skip to content

Add support for writing binary to file system#86

Open
inokawa wants to merge 2 commits intounifiedjs:mainfrom
inokawa:main
Open

Add support for writing binary to file system#86
inokawa wants to merge 2 commits intounifiedjs:mainfrom
inokawa:main

Conversation

@inokawa
Copy link

@inokawa inokawa commented Jan 4, 2026

Initial checklist

  • I read the support docs
  • I read the contributing guide
  • I agree to follow the code of conduct
  • I searched issues and discussions and couldn’t find anything or linked relevant results below
  • I made sure the docs are up to date
  • I included tests (or that’s not needed)

Description of changes

https://github.com/orgs/remarkjs/discussions/1473

This PR removes the stringification of Uint8Array before writing to the file system, that allows us outputting binary data from compiler (e.g. .docx, images) with cli like remark-cli.

@github-actions github-actions bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels Jan 4, 2026
@codecov
Copy link

codecov bot commented Jan 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (6f35eae) to head (82f06c9).

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #86   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           23        23           
  Lines         3214      3214           
=========================================
  Hits          3214      3214           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@inokawa inokawa marked this pull request as ready for review January 4, 2026 11:18
test/output.js Outdated
await t.test('should write binary to a path', async function () {
const cwd = new URL('simple-structure/', fixtures)
const stderr = spy()
const binary = () => new Uint8Array([0xde, 0xad, 0xbe, 0xef])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrapper function seems unneeded, can just copy/paste the value twice?
Or, stash the return value directly in the variable?
Also, more vaguely, what’s a good test for binary? What did you pick? Were there alternatives you considered?

Copy link
Author

@inokawa inokawa Jan 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem was non-UTF-8 string data was transformed to UTF-8 string data by TextDecoder before saving. I've added a new test with an Uint8Array including UTF-8 string for clarification (it will succeed with/without the fix).

I'm not an expert on handling binary in JS, but I think we can say the data is the same if the values at every indexes in a TypedArray like Uint8Array is the same. I used deepStrictEqual for that. I'm not sure we need to check data wrapped with other TypedArrays like Float16Array also.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🤞 phase/open Post is being triaged manually

Development

Successfully merging this pull request may close these issues.

2 participants