@@ -723,6 +723,8 @@ async function readDir(
723723interface ReadFileOptions {
724724 /** Base directory for `path` */
725725 baseDir ?: BaseDirectory
726+ /** Text encoding to use when reading a text file. Defaults to 'utf-8'. */
727+ encoding ?: string
726728}
727729
728730/**
@@ -753,7 +755,7 @@ async function readFile(
753755}
754756
755757/**
756- * Reads and returns the entire contents of a file as UTF-8 string .
758+ * Reads and returns the entire contents of a file as a string using the specified encoding (default: UTF-8) .
757759 * @example
758760 * ```typescript
759761 * import { readTextFile, BaseDirectory } from '@tauri-apps/plugin-fs';
@@ -777,11 +779,11 @@ async function readTextFile(
777779
778780 const bytes = arr instanceof ArrayBuffer ? arr : Uint8Array . from ( arr )
779781
780- return new TextDecoder ( ) . decode ( bytes )
782+ return new TextDecoder ( options ?. encoding ?? 'utf-8' ) . decode ( bytes )
781783}
782784
783785/**
784- * Returns an async {@linkcode AsyncIterableIterator} over the lines of a file as UTF-8 string .
786+ * Returns an async {@linkcode AsyncIterableIterator} over the lines of a file, decoded using the specified encoding (default: UTF-8) .
785787 * @example
786788 * ```typescript
787789 * import { readTextFileLines, BaseDirectory } from '@tauri-apps/plugin-fs';
@@ -838,7 +840,7 @@ async function readTextFileLines(
838840 return { value : null , done }
839841 }
840842
841- const line = new TextDecoder ( ) . decode (
843+ const line = new TextDecoder ( options ?. encoding ?? 'utf-8' ) . decode (
842844 bytes . slice ( 0 , bytes . byteLength - 1 )
843845 )
844846
0 commit comments