This repository has been archived on 2025-07-31. You can view files and clone it, but cannot push or open issues or pull requests.
Files
terminally-online/patches/react-native-file-access+3.0.4.patch
2023-07-30 16:07:06 +03:00

170 lines
7.6 KiB
Diff

diff --git a/node_modules/react-native-file-access/README.md b/node_modules/react-native-file-access/README.md
index e0540e0..9eb3295 100644
--- a/node_modules/react-native-file-access/README.md
+++ b/node_modules/react-native-file-access/README.md
@@ -155,6 +155,12 @@ type ManagedFetchResult = {
- Read the content of a file.
- Default encoding of returned string is utf8.
+`FileSystem.read(path: string, length?: number, position?: number): Promise<number[]>`
+
+- Read a file as a byte array.
+ - `length` - Optional number of bytes to read.
+ - `position` - Optional position to start reading from.
+
```
FileSystem.stat(path: string): Promise<FileStat>
diff --git a/node_modules/react-native-file-access/android/src/main/java/com/alpha0010/fs/FileAccessModule.kt b/node_modules/react-native-file-access/android/src/main/java/com/alpha0010/fs/FileAccessModule.kt
index 248a938..cbd4fe7 100644
--- a/node_modules/react-native-file-access/android/src/main/java/com/alpha0010/fs/FileAccessModule.kt
+++ b/node_modules/react-native-file-access/android/src/main/java/com/alpha0010/fs/FileAccessModule.kt
@@ -13,6 +13,8 @@ import com.facebook.react.bridge.Promise
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.ReactMethod
import com.facebook.react.bridge.ReadableMap
+import com.facebook.react.bridge.WritableArray
+import com.facebook.react.bridge.WritableNativeArray
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
@@ -400,6 +402,27 @@ class FileAccessModule internal constructor(context: ReactApplicationContext) :
}
}
+ @ReactMethod
+ override fun read(path: String, length: Double, position: Double, promise: Promise) {
+ ioScope.launch {
+ try {
+ val data = openForReading(path).use {
+ it.skip(position.toLong())
+ val byteArray = ByteArray(length.toInt())
+ it.read(byteArray)
+ byteArray
+ }
+ val writableArray: WritableArray = WritableNativeArray()
+ for (byte in data) {
+ writableArray.pushInt(byte.toInt() and 0xFF)
+ }
+ promise.resolve(writableArray)
+ } catch (e: Throwable) {
+ promise.reject(e)
+ }
+ }
+ }
+
@ReactMethod
override fun stat(path: String, promise: Promise) {
ioScope.launch {
diff --git a/node_modules/react-native-file-access/android/src/oldarch/FileAccessSpec.kt b/node_modules/react-native-file-access/android/src/oldarch/FileAccessSpec.kt
index 736324b..c223276 100644
--- a/node_modules/react-native-file-access/android/src/oldarch/FileAccessSpec.kt
+++ b/node_modules/react-native-file-access/android/src/oldarch/FileAccessSpec.kt
@@ -30,6 +30,7 @@ abstract class FileAccessSpec internal constructor(context: ReactApplicationCont
abstract fun mkdir(path: String, promise: Promise)
abstract fun mv(source: String, target: String, promise: Promise)
abstract fun readFile(path: String, encoding: String, promise: Promise)
+ abstract fun read(path: String, length: Double, position: Double, promise: Promise)
abstract fun stat(path: String, promise: Promise)
abstract fun statDir(path: String, promise: Promise)
abstract fun unlink(path: String, promise: Promise)
diff --git a/node_modules/react-native-file-access/lib/commonjs/index.js b/node_modules/react-native-file-access/lib/commonjs/index.js
index 88f1c2c..20eb70b 100644
--- a/node_modules/react-native-file-access/lib/commonjs/index.js
+++ b/node_modules/react-native-file-access/lib/commonjs/index.js
@@ -209,6 +209,12 @@ const FileSystem = {
let encoding = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'utf8';
return FileAccessNative.readFile(path, encoding);
},
+ /**
+ * Read the content of a file as a byte array.
+ */
+ read(path, length, position) {
+ return FileAccessNative.read(path, length, position);
+ },
/**
* Read file metadata.
*/
diff --git a/node_modules/react-native-file-access/lib/module/index.js b/node_modules/react-native-file-access/lib/module/index.js
index 0581920..22c37d3 100644
--- a/node_modules/react-native-file-access/lib/module/index.js
+++ b/node_modules/react-native-file-access/lib/module/index.js
@@ -198,6 +198,12 @@ export const FileSystem = {
let encoding = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'utf8';
return FileAccessNative.readFile(path, encoding);
},
+ /**
+ * Read the content of a file as a byte array.
+ */
+ read(path, length, position) {
+ return FileAccessNative.read(path, length, position);
+ },
/**
* Read file metadata.
*/
diff --git a/node_modules/react-native-file-access/lib/typescript/NativeFileAccess.d.ts b/node_modules/react-native-file-access/lib/typescript/NativeFileAccess.d.ts
index 0c58874..ed84081 100644
--- a/node_modules/react-native-file-access/lib/typescript/NativeFileAccess.d.ts
+++ b/node_modules/react-native-file-access/lib/typescript/NativeFileAccess.d.ts
@@ -63,6 +63,7 @@ export interface Spec extends TurboModule {
mkdir(path: string): Promise<string>;
mv(source: string, target: string): Promise<void>;
readFile(path: string, encoding: string): Promise<string>;
+ read(path: string, length: number, position: number): Promise<number[]>;
stat(path: string): Promise<FileStat>;
statDir(path: string): Promise<FileStat[]>;
unlink(path: string): Promise<void>;
diff --git a/node_modules/react-native-file-access/lib/typescript/index.d.ts b/node_modules/react-native-file-access/lib/typescript/index.d.ts
index 5433d53..12854ca 100644
--- a/node_modules/react-native-file-access/lib/typescript/index.d.ts
+++ b/node_modules/react-native-file-access/lib/typescript/index.d.ts
@@ -84,6 +84,10 @@ export declare const FileSystem: {
* Read the content of a file.
*/
readFile(path: string, encoding?: Encoding): Promise<string>;
+ /**
+ * Read the content of a file as a byte array.
+ */
+ read(path: string, length?: number, position?: number): Promise<number[]>;
/**
* Read file metadata.
*/
diff --git a/node_modules/react-native-file-access/src/NativeFileAccess.ts b/node_modules/react-native-file-access/src/NativeFileAccess.ts
index b3a7baa..affd76c 100644
--- a/node_modules/react-native-file-access/src/NativeFileAccess.ts
+++ b/node_modules/react-native-file-access/src/NativeFileAccess.ts
@@ -71,6 +71,7 @@ export interface Spec extends TurboModule {
mkdir(path: string): Promise<string>;
mv(source: string, target: string): Promise<void>;
readFile(path: string, encoding: string): Promise<string>;
+ read(path: string, length: number, position: number): Promise<number[]>;
stat(path: string): Promise<FileStat>;
statDir(path: string): Promise<FileStat[]>;
unlink(path: string): Promise<void>;
diff --git a/node_modules/react-native-file-access/src/index.ts b/node_modules/react-native-file-access/src/index.ts
index 1b38d45..5c9fd5e 100644
--- a/node_modules/react-native-file-access/src/index.ts
+++ b/node_modules/react-native-file-access/src/index.ts
@@ -31,7 +31,6 @@ const LINKING_ERROR =
'- You rebuilt the app after installing the package\n' +
'- You are not using Expo Go\n';
-// @ts-expect-error
const isTurboModuleEnabled = global.__turboModuleProxy != null;
const FileAccessModule = isTurboModuleEnabled
@@ -275,6 +274,13 @@ export const FileSystem = {
return FileAccessNative.readFile(path, encoding);
},
+ /**
+ * Read the content of a file as a byte array.
+ */
+ read(path: string, length: number = 1000, position: number = 0) {
+ return FileAccessNative.read(path, length, position);
+ },
+
/**
* Read file metadata.
*/