react-native-fs-turbo 0.1.5 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +149 -21
- package/RNFSTurbo.podspec +1 -0
- package/cpp/RNFSTurboHostObject.cpp +348 -180
- package/cpp/RNFSTurboLogger.h +10 -0
- package/cpp/RNFSTurboPlatformHelper.h +2 -0
- package/cpp/filesystem/helpers.cpp +69 -11
- package/cpp/filesystem/helpers.h +7 -0
- package/ios/PrivacyInfo.xcprivacy +30 -0
- package/ios/RNFSTurboPlatformHelper.mm +19 -0
- package/lib/commonjs/RNFSTurbo.js +21 -21
- package/lib/commonjs/RNFSTurbo.js.map +1 -1
- package/lib/module/RNFSTurbo.js +21 -21
- package/lib/module/RNFSTurbo.js.map +1 -1
- package/lib/typescript/RNFSTurbo.d.ts +11 -11
- package/lib/typescript/RNFSTurbo.d.ts.map +1 -1
- package/lib/typescript/Types.d.ts +28 -15
- package/lib/typescript/Types.d.ts.map +1 -1
- package/package.json +2 -1
- package/src/RNFSTurbo.ts +38 -24
- package/src/Types.ts +51 -18
package/README.md
CHANGED
|
@@ -102,12 +102,15 @@ import RNFSTurbo from 'react-native-fs-turbo';
|
|
|
102
102
|
const pathUtf8 = `${RNFSTurbo.DocumentDirectoryPath}/test_utf8.txt`;
|
|
103
103
|
const pathBase64 = `${RNFSTurbo.DocumentDirectoryPath}/test_base64.txt`;
|
|
104
104
|
const pathUint8 = `${RNFSTurbo.DocumentDirectoryPath}/test_uint8.txt`;
|
|
105
|
+
const pathFloat32 = `${RNFSTurbo.DocumentDirectoryPath}/test_float32.txt`;
|
|
105
106
|
|
|
106
107
|
try {
|
|
107
108
|
RNFSTurbo.writeFile(path, 'Lorem ipsum dolor sit amet', 'utf8');
|
|
108
109
|
RNFSTurbo.writeFile(path, 'TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQ=', 'base64');
|
|
109
110
|
// An array with uint8 can be passed as input data
|
|
110
111
|
RNFSTurbo.writeFile(path, [76, 111, 114, 101, 109, 32, 105, 112, 115, 117, 109, 32, 100, 111, 108, 111, 114, 32, 115, 105, 116, 32, 97, 109, 101, 116], 'uint8');
|
|
112
|
+
// An array with float32 can be passed as input data
|
|
113
|
+
RNFSTurbo.writeFile(path, [0.4233244061470032, 0.5435456037521362, 2.5345540046691895, 7.2343244552612305, 3.867867946624756, 0.7876875996589661], 'float32');
|
|
111
114
|
} catch (err: Error) {
|
|
112
115
|
console.log(err.message);
|
|
113
116
|
}
|
|
@@ -275,58 +278,175 @@ type ReadDirItem = {
|
|
|
275
278
|
|
|
276
279
|
Node.js style version of `readDir` that returns only the names. Note the lowercase `d`.
|
|
277
280
|
|
|
278
|
-
### `readFile(filepath: string,
|
|
281
|
+
### `readFile(filepath: string, options?: ReadOptions): string | number[]`
|
|
279
282
|
|
|
280
|
-
Reads the file at `path` and return contents. `
|
|
283
|
+
Reads the file at `path` and return contents. `options` can be string of encrypted types or object, default is `utf8`. Use `base64` or `uint8` or `float32` encoding for reading binary files.
|
|
284
|
+
|
|
285
|
+
```ts
|
|
286
|
+
type ReadOptions =
|
|
287
|
+
| 'utf8' | 'ascii' | 'base64' | 'uint8' | 'float32'
|
|
288
|
+
| { encoding: 'utf8' | 'ascii' | 'base64' | 'uint8' | 'float32' };
|
|
289
|
+
```
|
|
281
290
|
|
|
282
291
|
Note: you will take quite a performance hit if you are reading big files
|
|
283
292
|
|
|
284
|
-
### `read(filepath: string, length: number, position: number,
|
|
293
|
+
### `read(filepath: string, length: number, position: number, options?: ReadOptions): string | number[]`
|
|
285
294
|
|
|
286
|
-
Reads `length` bytes from the given `position` of the file at `path` and returns contents. `
|
|
295
|
+
Reads `length` bytes from the given `position` of the file at `path` and returns contents. `options` can be string of encrypted types or object, default is `utf8`. Use `base64` or `uint8` or `float32` encoding for reading binary files.
|
|
296
|
+
|
|
297
|
+
```ts
|
|
298
|
+
type ReadOptions =
|
|
299
|
+
| 'utf8' | 'ascii' | 'base64' | 'uint8' | 'float32'
|
|
300
|
+
| { encoding: 'utf8' | 'ascii' | 'base64' | 'uint8' | 'float32' };
|
|
301
|
+
```
|
|
287
302
|
|
|
288
303
|
Note: reading big files piece by piece using this method may be useful in terms of performance.
|
|
304
|
+
Note: `float32` size is 4 bytes, so `position` and `length` should be specified in bytes (multiplied by 4)
|
|
289
305
|
|
|
290
|
-
### (Android only) `readFileAssets(filepath: string,
|
|
306
|
+
### (Android only) `readFileAssets(filepath: string, options?: ReadOptions) => string[]`
|
|
291
307
|
|
|
292
|
-
Reads the file at `path` in the Android app's assets folder and return contents. `
|
|
308
|
+
Reads the file at `path` in the Android app's assets folder and return contents. `options` can be string of encrypted types or object, default is `utf8`. Use `base64` encoding for reading binary files.
|
|
293
309
|
|
|
294
310
|
`filepath` is the relative path to the file from the root of the `assets` folder.
|
|
295
311
|
|
|
296
|
-
|
|
312
|
+
```ts
|
|
313
|
+
type ReadOptions =
|
|
314
|
+
| 'utf8' | 'ascii' | 'base64'
|
|
315
|
+
| { encoding: 'utf8' | 'ascii' | 'base64' };
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
### (Android only) `readFileRes: (filepath: string, options?: ReadOptions) => string[]`
|
|
319
|
+
|
|
320
|
+
Reads the file named `filename` in the Android app's `res` folder and return contents. Only the file name (not folder) needs to be specified. The file type will be detected from the extension and automatically located within `res/drawable` (for image files) or `res/raw` (for everything else). `options` can be string of encrypted types or object, default is `utf8`. Use `base64` encoding for reading binary files.
|
|
321
|
+
|
|
322
|
+
```ts
|
|
323
|
+
type ReadOptions =
|
|
324
|
+
| 'utf8' | 'ascii' | 'base64'
|
|
325
|
+
| { encoding: 'utf8' | 'ascii' };
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
### `writeFile(filepath: string, contents: string | number[], options?: WriteOptions): void`
|
|
329
|
+
|
|
330
|
+
Write the `contents` to `filepath`. `options` can be string of encrypted types or object, default is `utf8`
|
|
331
|
+
|
|
332
|
+
```ts
|
|
333
|
+
type WriteOptions =
|
|
334
|
+
| 'utf8' | 'ascii' | 'base64' | 'uint8' | 'float32'
|
|
335
|
+
| {
|
|
336
|
+
encoding?: 'utf8' | 'ascii' | 'base64' | 'uint8' | 'float32',
|
|
337
|
+
NSFileProtectionKey?:
|
|
338
|
+
|"NSFileProtectionNone"
|
|
339
|
+
| "NSFileProtectionComplete"
|
|
340
|
+
| "NSFileProtectionCompleteUnlessOpen"
|
|
341
|
+
| "NSFileProtectionCompleteUntilFirstUserAuthentication"
|
|
342
|
+
| "NSFileProtectionCompleteWhenUserInactive" // iOS 17+ only
|
|
343
|
+
};
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
(IOS only): `options.NSFileProtectionKey` property can be provided to set this attribute on iOS platforms.
|
|
297
347
|
|
|
298
|
-
|
|
348
|
+
### `appendFile(filepath: string, contents: string | number[], options?: WriteOptions): void`
|
|
299
349
|
|
|
300
|
-
|
|
350
|
+
Append the `contents` to `filepath`. `encoding` can be string of encrypted types or object, default is `utf8`.
|
|
301
351
|
|
|
302
|
-
|
|
352
|
+
```ts
|
|
353
|
+
type WriteOptions =
|
|
354
|
+
| 'utf8' | 'ascii' | 'base64' | 'uint8' | 'float32'
|
|
355
|
+
| {
|
|
356
|
+
encoding?: 'utf8' | 'ascii' | 'base64' | 'uint8' | 'float32',
|
|
357
|
+
NSFileProtectionKey?:
|
|
358
|
+
|"NSFileProtectionNone"
|
|
359
|
+
| "NSFileProtectionComplete"
|
|
360
|
+
| "NSFileProtectionCompleteUnlessOpen"
|
|
361
|
+
| "NSFileProtectionCompleteUntilFirstUserAuthentication"
|
|
362
|
+
| "NSFileProtectionCompleteWhenUserInactive" // iOS 17+ only
|
|
363
|
+
};
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
(IOS only): `options.NSFileProtectionKey` property can be provided to set this attribute on iOS platforms.
|
|
303
367
|
|
|
304
|
-
### `
|
|
368
|
+
### `write(filepath: string, contents: string | number[], position?: number, options?: WriteOptions): void`
|
|
305
369
|
|
|
306
|
-
|
|
370
|
+
Write the `contents` to `filepath` at the given random access position. When `position` is `undefined` or `-1` the contents is appended to the end of the file. `encoding` can be string of encrypted types or object, default is `utf8`.
|
|
371
|
+
|
|
372
|
+
```ts
|
|
373
|
+
type WriteOptions =
|
|
374
|
+
| 'utf8' | 'ascii' | 'base64' | 'uint8' | 'float32'
|
|
375
|
+
| {
|
|
376
|
+
encoding?: 'utf8' | 'ascii' | 'base64' | 'uint8' | 'float32',
|
|
377
|
+
NSFileProtectionKey?:
|
|
378
|
+
|"NSFileProtectionNone"
|
|
379
|
+
| "NSFileProtectionComplete"
|
|
380
|
+
| "NSFileProtectionCompleteUnlessOpen"
|
|
381
|
+
| "NSFileProtectionCompleteUntilFirstUserAuthentication"
|
|
382
|
+
| "NSFileProtectionCompleteWhenUserInactive" // iOS 17+ only
|
|
383
|
+
};
|
|
384
|
+
```
|
|
307
385
|
|
|
308
|
-
|
|
386
|
+
Note: `float32` size is 4 bytes, so `position` should be specified in bytes (multiplied by 4)
|
|
309
387
|
|
|
310
|
-
|
|
388
|
+
(IOS only): `options.NSFileProtectionKey` property can be provided to set this attribute on iOS platforms.
|
|
311
389
|
|
|
312
|
-
### `moveFile(filepath: string, destPath: string): void`
|
|
390
|
+
### `moveFile(filepath: string, destPath: string, options?: MoveCopyOptions): void`
|
|
313
391
|
|
|
314
392
|
Moves the file located at `filepath` to `destPath`. This is more performant than reading and then re-writing the file data because the move is done natively and the data doesn't have to be copied or cross the bridge.
|
|
315
393
|
|
|
394
|
+
```ts
|
|
395
|
+
type MoveCopyOptions =
|
|
396
|
+
| {
|
|
397
|
+
NSFileProtectionKey?:
|
|
398
|
+
|"NSFileProtectionNone"
|
|
399
|
+
| "NSFileProtectionComplete"
|
|
400
|
+
| "NSFileProtectionCompleteUnlessOpen"
|
|
401
|
+
| "NSFileProtectionCompleteUntilFirstUserAuthentication"
|
|
402
|
+
| "NSFileProtectionCompleteWhenUserInactive" // iOS 17+ only
|
|
403
|
+
};
|
|
404
|
+
```
|
|
405
|
+
|
|
316
406
|
Note: Overwrites existing file
|
|
317
407
|
|
|
318
|
-
|
|
408
|
+
(IOS only): `options.NSFileProtectionKey` property can be provided to set this attribute on iOS platforms.
|
|
409
|
+
|
|
410
|
+
### `copyFolder(srcFolderPath: string, destFolderPath: string, options?: MoveCopyOptions): void`
|
|
319
411
|
|
|
320
412
|
Copies the contents located at `srcFolderPath` to `destFolderPath`.
|
|
321
413
|
|
|
414
|
+
```ts
|
|
415
|
+
type MoveCopyOptions =
|
|
416
|
+
| {
|
|
417
|
+
NSFileProtectionKey?:
|
|
418
|
+
|"NSFileProtectionNone"
|
|
419
|
+
| "NSFileProtectionComplete"
|
|
420
|
+
| "NSFileProtectionCompleteUnlessOpen"
|
|
421
|
+
| "NSFileProtectionCompleteUntilFirstUserAuthentication"
|
|
422
|
+
| "NSFileProtectionCompleteWhenUserInactive" // iOS 17+ only
|
|
423
|
+
};
|
|
424
|
+
```
|
|
425
|
+
|
|
322
426
|
Note: Recursively replaces all files and folders
|
|
323
427
|
|
|
324
|
-
|
|
428
|
+
(IOS only): `options.NSFileProtectionKey` property can be provided to set this attribute on iOS platforms.
|
|
429
|
+
|
|
430
|
+
### `copyFile(filepath: string, destPath: string, options?: MoveCopyOptions): void`
|
|
325
431
|
|
|
326
432
|
Copies the file located at `filepath` to `destPath`.
|
|
327
433
|
|
|
434
|
+
```ts
|
|
435
|
+
type MoveCopyOptions =
|
|
436
|
+
| {
|
|
437
|
+
NSFileProtectionKey?:
|
|
438
|
+
|"NSFileProtectionNone"
|
|
439
|
+
| "NSFileProtectionComplete"
|
|
440
|
+
| "NSFileProtectionCompleteUnlessOpen"
|
|
441
|
+
| "NSFileProtectionCompleteUntilFirstUserAuthentication"
|
|
442
|
+
| "NSFileProtectionCompleteWhenUserInactive" // iOS 17+ only
|
|
443
|
+
};
|
|
444
|
+
```
|
|
445
|
+
|
|
328
446
|
Note: Error will be thrown if the file already exists.
|
|
329
447
|
|
|
448
|
+
(IOS only): `options.NSFileProtectionKey` property can be provided to set this attribute on iOS platforms.
|
|
449
|
+
|
|
330
450
|
### (Android only) `copyFileAssets(filepath: string, destPath: string): void`
|
|
331
451
|
|
|
332
452
|
Copies the file at `filepath` in the Android app's assets folder and copies it to the given `destPath ` path.
|
|
@@ -443,12 +563,20 @@ Note: `ctime` no longer supported
|
|
|
443
563
|
Create a directory at `filepath`. Automatically creates parents and does not throw if already exists (works like Linux `mkdir -p`).
|
|
444
564
|
|
|
445
565
|
```ts
|
|
446
|
-
type MkdirOptions =
|
|
447
|
-
|
|
448
|
-
|
|
566
|
+
type MkdirOptions =
|
|
567
|
+
| {
|
|
568
|
+
NSFileProtectionKey?:
|
|
569
|
+
|"NSFileProtectionNone"
|
|
570
|
+
| "NSFileProtectionComplete"
|
|
571
|
+
| "NSFileProtectionCompleteUnlessOpen"
|
|
572
|
+
| "NSFileProtectionCompleteUntilFirstUserAuthentication"
|
|
573
|
+
| "NSFileProtectionCompleteWhenUserInactive"; // iOS 17+ only
|
|
574
|
+
NSURLIsExcludedFromBackupKey?: boolean;
|
|
575
|
+
};
|
|
449
576
|
```
|
|
450
577
|
|
|
451
|
-
(IOS only):
|
|
578
|
+
(IOS only): `options.NSFileProtectionKey` property can be provided to set this attribute on iOS platforms.
|
|
579
|
+
(IOS only): The `options.NSURLIsExcludedFromBackupKey` property can be provided to set this attribute on iOS platforms. Apple will *reject* apps for storing offline cache data that does not have this attribute.
|
|
452
580
|
|
|
453
581
|
### `downloadFile(options: DownloadFileOptions, completeCallback?: DownloadResultFunc, errorCallback?: DownloadErrorFunc): DownloadResult | Promise<DownloadResult>`
|
|
454
582
|
|
package/RNFSTurbo.podspec
CHANGED