-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Add mode option to Bun.write() for setting file permissions #21601
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
robobun
wants to merge
4
commits into
main
Choose a base branch
from
claude/add-mode-option-to-bun-write
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This implements the mode option for Bun.write() to allow setting file permissions on POSIX systems, similar to Node.js fs.writeFile(). The implementation covers all write code paths: - Main Bun.write() function in Blob.zig - Async file writing in write_file.zig - File copying in copy_file.zig - S3File write method Key changes: - Added mode field to WriteFileOptions struct - Updated all write functions to accept and use mode parameter - Added fchmod() calls after file creation on POSIX systems - Added comprehensive tests covering various write scenarios - Mode validation follows Node.js behavior (truncates to 0o777) Tests verify mode setting works correctly for string data, binary data, blob operations, file copying, and various edge cases. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
Fixed type casting issues where u32 mode values were being passed to functions expecting u16 (bun.Mode) on macOS. Added @intcast() wrappers for: - bun.sys.open() mode parameters in Blob.zig - bun.sys.fchmod() mode parameters in Blob.zig, copy_file.zig, and write_file.zig All cross-platform builds now pass with `bun run zig:check-all`. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
Eliminates @intcast() calls by using the proper bun.Mode type throughout the codebase instead of u32. This improves type safety and removes platform-specific casting issues between u16 and u32. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
cirospaciari
reviewed
Aug 5, 2025
var mode: ?bun.Mode = null; | ||
|
||
// Parse mode from options if present | ||
if (options) |options_object| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont think this has any meaning for s3 right? we can just throw an error here or just ignore it instead of parsing it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 I would expect it to error
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
mode
option toBun.write()
to allow setting file permissions on POSIX systemsImplementation Details
This PR implements the
mode
option forBun.write()
similar to Node.jsfs.writeFile()
. The implementation includes:Core Changes
Key Features
modeFromJS()
with truncation to 0o777)createPath
Usage Examples
Test Plan
createPath
optionbun run zig:check-all
🤖 Generated with Claude Code