Skip to content

feat(fs): #3243 add encoding option to readTextFile functions#3244

Merged
amrbashir merged 3 commits intotauri-apps:v2from
SeijiOkuda:v2-fs-readTextFile
Feb 9, 2026
Merged

feat(fs): #3243 add encoding option to readTextFile functions#3244
amrbashir merged 3 commits intotauri-apps:v2from
SeijiOkuda:v2-fs-readTextFile

Conversation

@SeijiOkuda
Copy link
Copy Markdown
Contributor

@SeijiOkuda SeijiOkuda commented Feb 1, 2026

Summary

Added support for reading text files encoded in character sets other than UTF-8 (e.g. Shift_JIS).

Previously, the application assumed UTF-8 encoding, which caused garbled text in some cases. With this change, multiple character encodings are now supported and such files can be read correctly.

Closes #3243

Changes

  • Added support for reading files saved in encodings other than UTF-8
  • Added logic to specify and/or detect the character encoding and decode accordingly
  • Confirmed that existing behavior for UTF-8 files is not affected

Background / Motivation

  • To support existing memo/text files that are saved in encodings such as Shift_JIS
  • To allow users to handle text files without character corruption

Verification

  • Confirmed that UTF-8 files can still be read as before
  • Confirmed that files encoded in Shift_JIS and other encodings are displayed correctly

Usage

You can specify the encoding when reading a text file:

await readTextFile(path, { encoding: "shift_jis" });

@SeijiOkuda SeijiOkuda requested a review from a team as a code owner February 1, 2026 13:38
@SeijiOkuda SeijiOkuda changed the title feat(fs): #3243 add encoding option to readFile and readTextFile functions feat(fs): #3243 add encoding option to readTextFile functions Feb 1, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 1, 2026

Package Changes Through 5ad3d80

There are 2 changes which include fs with minor, fs-js with minor

Planned Package Versions

The following package releases are the planned based on the context of changes in this pull request.

package current next
api-example 2.0.41 2.0.42
api-example-js 2.0.37 2.0.38
fs 2.4.5 2.5.0
fs-js 2.4.5 2.5.0
dialog 2.6.0 2.6.1
dialog-js 2.6.0 2.6.1
http 2.5.7 2.5.8
http-js 2.5.7 2.5.8
persisted-scope 2.3.5 2.3.6

Add another change file through the GitHub UI by following this link.


Read about change files or the docs at github.com/jbolda/covector

Copy link
Copy Markdown
Member

@amrbashir amrbashir left a comment

Choose a reason for hiding this comment

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

Can you please add a change file and also update readTextFileLines to do the same decoding

/** Base directory for `path` */
baseDir?: BaseDirectory
baseDir?: BaseDirectory,
encoding?: string
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Missing documentation

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@amrbashir
Thanks for the review!
Added documentation comments.

@SeijiOkuda
Copy link
Copy Markdown
Contributor Author

Can you please add a change file and also update readTextFileLines to do the same decoding

@amrbashir
Thanks for the review!
Done! I added the change file and updated readTextFileLines to apply the same decoding as well.

@aiueo13
Copy link
Copy Markdown
Contributor

aiueo13 commented Feb 9, 2026

readTextFileLines detects line breaks on the Rust side using a byte-level check of \n and \r\n for 0x0A and 0x0D 0x0A. Therefore, for encodings that are not compatible with this approach. it may be necessary to either return an error or change the implementation.😱

impl<B: BufRead> Iterator for LinesBytes<B> {
type Item = std::io::Result<Vec<u8>>;
fn next(&mut self) -> Option<std::io::Result<Vec<u8>>> {
let mut buf = Vec::new();
match self.0.read_until(b'\n', &mut buf) {
Ok(0) => None,
Ok(_n) => {
if buf.last() == Some(&b'\n') {
buf.pop();
if buf.last() == Some(&b'\r') {
buf.pop();
}
}
Some(Ok(buf))
}
Err(e) => Some(Err(e)),
}
}
}

@amrbashir
Copy link
Copy Markdown
Member

I think that could be fixed in another PR

@amrbashir amrbashir merged commit e97a4de into tauri-apps:v2 Feb 9, 2026
11 checks passed
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.

feat(fs): add encoding option to readTextFile (support non-UTF-8 files)

3 participants