Skip to content
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

Port writeFileSync to write_file.ts, add writeFile and tests #728

Merged
merged 3 commits into from
Sep 11, 2018

Conversation

kevinkassimo
Copy link
Contributor

Based on #567 (fixed, rebased and reformatted to match master requirements)

  • Move writeFileSync to write_file.ts
  • Create (async) writeFile
  • Add tests for writeFile

@hayd
Copy link
Contributor

hayd commented Sep 11, 2018

Aside: is 644 a better permissions default (over 666)?

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

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

Thanks! Just a few comments -

const enc = new TextEncoder();
const data = enc.encode("Hello");
const filename = "/baddir/test.txt";
// The following should fail because /baddir doesn't exist (hopefully).
Copy link
Member

Choose a reason for hiding this comment

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

This comment is wrong - it fails because of permission.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resolved - Sorry for forgetting to update the comment

js/write_file.ts Outdated

/**
* Write a new file, with given filename and data synchronously.
* import { writeFileSync } from "deno";
Copy link
Member

Choose a reason for hiding this comment

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

Line break before example

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added

assertEqual("Hello", actual);
});

testPerm({ write: true }, async function writeFileFail() {
Copy link
Member

Choose a reason for hiding this comment

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

Change test name to writeFileNotFound

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@kevinkassimo
Copy link
Contributor Author

kevinkassimo commented Sep 11, 2018

@hayd Both Node (fs.writeFile) and Ruby (IO.sysopen) is using 0o666 as default, while Python uses 0o777 for os.open(...). Also, one of the most common umask is 0o022. There are a lot of options and 0o644 is also fine.

0o666 also comes from #567 which I based this PR on, which I thought is okay. Probably won't change it unless there are some compelling reasons

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

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

LGTM

@ry ry merged commit 05f87a0 into denoland:master Sep 11, 2018
@kevinkassimo kevinkassimo deleted the fs/writeFile branch December 27, 2019 07:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants