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

Added read file str #276

Merged
merged 7 commits into from
Apr 13, 2019
Merged

Added read file str #276

merged 7 commits into from
Apr 13, 2019

Conversation

zekth
Copy link
Contributor

@zekth zekth commented Mar 14, 2019

As discussed in : denoland/deno#1925
Moving readFileStr / readFileStrSync to fs-extra

@j-f1
Copy link

j-f1 commented Mar 14, 2019

How about defaulting encoding to utf-8?
Edit: that’s actually the default for TextDecoder already.

@zekth
Copy link
Contributor Author

zekth commented Mar 14, 2019

How about defaulting encoding to utf-8?

Definitely legit.

* Read file synchronously and output it as a string.
*
* @param filename File to read
* @param encoding Encoding of the file. Default = "utf-8"
Copy link

Choose a reason for hiding this comment

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

JSDoc supports specifying defaults:

Suggested change
* @param encoding Encoding of the file. Default = "utf-8"
* @param [encoding="utf-8"] Encoding of the file.

However, since TextDecoder defaults to ITF-8, should this just pass on undefined?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

JSDoc supports defaults Without the type definition? Thought it was needed due to my linter. My bad.
About the undefined value, it may be better to have the default in the jsdoc instead of using implicit default for automatic API documentation. Don't you think?

* @param filename File to read
* @param [encoding="utf-8"] Encoding of the file
*/
export async function readFileStr(
Copy link
Contributor

Choose a reason for hiding this comment

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

how about

Suggested change
export async function readFileStr(
export async function readFile(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

May be confusing with the Deno.readFile no?

Copy link
Contributor

@axetroy axetroy Mar 14, 2019

Choose a reason for hiding this comment

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

@zekth
fs module is used to add some quick and easy methods

Returning a string is the most common method for developer

In most cases, Deno.readFile returns the Reader is not commonly used

So I don’t think these conflicts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Totally agree with you. First it was named like this to be in Deno and not in fs-extra as you can see in the ref.

*/
export async function readFileStr(
filename: string,
encoding: string = "utf-8"
Copy link
Contributor

Choose a reason for hiding this comment

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

encoding should be an options object in case of other fields in the future. eg flag

Suggested change
encoding: string = "utf-8"
options: ReadOptions = {}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Legit. Will add.

@axetroy axetroy mentioned this pull request Mar 14, 2019
13 tasks
fs/read_file.ts Outdated Show resolved Hide resolved
@zekth zekth mentioned this pull request Mar 18, 2019
@zekth
Copy link
Contributor Author

zekth commented Mar 19, 2019

Rebased and done the reviews @ry

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 b462ad2 into denoland:master Apr 13, 2019
@axetroy
Copy link
Contributor

axetroy commented Apr 14, 2019

Since there is a read interface, should there be a write interface?

@zekth zekth deleted the readfilestr branch April 14, 2019 09:03
ry pushed a commit to ry/deno that referenced this pull request Oct 9, 2019
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.

4 participants