expo-file-system 18.0.3 → 18.0.5

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/CHANGELOG.md CHANGED
@@ -10,6 +10,18 @@
10
10
 
11
11
  ### 💡 Others
12
12
 
13
+ ## 18.0.5 — 2024-12-10
14
+
15
+ ### 🐛 Bug fixes
16
+
17
+ - [macOS][next]: Add availability checks ([#33504](https://github.com/expo/expo/pull/33504) by [@hassankhan](https://github.com/hassankhan))
18
+
19
+ ## 18.0.4 — 2024-11-19
20
+
21
+ ### 🎉 New features
22
+
23
+ - [next] Added `.bytes()` and writing a `Uint8Array`. ([#33020](https://github.com/expo/expo/pull/33020) by [@aleqsio](https://github.com/aleqsio))
24
+
13
25
  ## 18.0.3 — 2024-11-13
14
26
 
15
27
  ### 🎉 New features
@@ -1,7 +1,7 @@
1
1
  apply plugin: 'com.android.library'
2
2
 
3
3
  group = 'host.exp.exponent'
4
- version = '18.0.3'
4
+ version = '18.0.5'
5
5
 
6
6
  def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
7
7
  apply from: expoModulesCorePlugin
@@ -14,7 +14,7 @@ android {
14
14
  namespace "expo.modules.filesystem"
15
15
  defaultConfig {
16
16
  versionCode 30
17
- versionName "18.0.3"
17
+ versionName "18.0.5"
18
18
  }
19
19
  }
20
20
 
@@ -53,7 +53,7 @@ class FileSystemFile(file: File) : FileSystemPath(file) {
53
53
  create()
54
54
  }
55
55
  FileOutputStream(file).use {
56
- it.write(content.toDirectBuffer().array())
56
+ it.channel.write(content.toDirectBuffer())
57
57
  }
58
58
  }
59
59
 
@@ -74,6 +74,12 @@ class FileSystemFile(file: File) : FileSystemPath(file) {
74
74
  return Base64.encodeToString(file.readBytes(), Base64.NO_WRAP)
75
75
  }
76
76
 
77
+ fun bytes(): ByteArray {
78
+ validateType()
79
+ validatePermission(Permission.READ)
80
+ return file.readBytes()
81
+ }
82
+
77
83
  @OptIn(ExperimentalStdlibApi::class)
78
84
  val md5: String get() {
79
85
  validatePermission(Permission.READ)
@@ -102,6 +102,10 @@ class FileSystemNextModule : Module() {
102
102
  file.base64()
103
103
  }
104
104
 
105
+ Function("bytes") { file: FileSystemFile ->
106
+ file.bytes()
107
+ }
108
+
105
109
  Property("exists") { file: FileSystemFile ->
106
110
  file.exists
107
111
  }
@@ -85,11 +85,16 @@ export declare class File {
85
85
  * @returns The contents of the file as a base64 string.
86
86
  */
87
87
  base64(): string;
88
+ /**
89
+ * Retrieves byte content of the entire file.
90
+ * @returns The contents of the file as a Uint8Array.
91
+ */
92
+ bytes(): Uint8Array;
88
93
  /**
89
94
  * Writes content to the file.
90
95
  * @param content - The content to write into the file.
91
96
  */
92
- write(content: string): void;
97
+ write(content: string | Uint8Array): void;
93
98
  /**
94
99
  * Deletes a file.
95
100
  *
@@ -1 +1 @@
1
- {"version":3,"file":"ExpoFileSystem.types.d.ts","sourceRoot":"","sources":["../../src/next/ExpoFileSystem.types.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,OAAO,SAAS;IAC5B;;;;;;;OAOG;gBACS,GAAG,IAAI,EAAE,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,EAAE;IAElD;;OAEG;IACH,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAErB;;;OAGG;IACH,YAAY,IAAI,IAAI;IAEpB;;;;OAIG;IACH,MAAM,IAAI,IAAI;IAEd;;;OAGG;IACH,MAAM,EAAE,OAAO,CAAC;IAEhB;;;;OAIG;IACH,MAAM,IAAI,IAAI;IAEd;;OAEG;IACH,IAAI,CAAC,WAAW,EAAE,SAAS,GAAG,IAAI;IAElC;;OAEG;IACH,IAAI,CAAC,WAAW,EAAE,SAAS,GAAG,IAAI;IAElC;;;;OAIG;IACH,aAAa,IAAI;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE;IAExD;;OAEG;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H,MAAM,IAAI,IAAI;IAEd;;OAEG;IACH,IAAI,CAAC,WAAW,EAAE,SAAS,GAAG,IAAI;IAElC;;OAEG;IACH,IAAI,CAAC,WAAW,EAAE,SAAS,GAAG,IAAI;IAElC;;;OAGG;IACH,IAAI,IAAI,UAAU;IAElB;;;;;;;;;OASG;IACH,MAAM,CAAC,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAEnF;;OAEG;IACH,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAEpB;;OAEG;IACH,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CACpB;AAED,MAAM,CAAC,OAAO,OAAO,UAAU;IAI7B,KAAK,IAAI,IAAI;IAKb,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU;IAKrC,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI;IAMnC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAItB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CACrB"}
@@ -102,7 +102,7 @@ internal func copyPHAsset(fromUrl: URL, toUrl: URL, with resourceManager: PHAsse
102
102
  }
103
103
 
104
104
  internal func isPhotoLibraryStatusAuthorized() -> Bool {
105
- if #available(iOS 14, tvOS 14, *) {
105
+ if #available(iOS 14, macOS 11, tvOS 14, *) {
106
106
  let status = PHPhotoLibrary.authorizationStatus(for: .readWrite)
107
107
  return status == .authorized || status == .limited
108
108
  }
@@ -73,8 +73,11 @@ internal final class FileSystemFile: FileSystemPath {
73
73
  try content.write(to: url, atomically: false, encoding: .utf8) // TODO: better error handling
74
74
  }
75
75
 
76
- // TODO: typedarray, blobs, others support
76
+ // TODO: blob support
77
77
  func write(_ content: TypedArray) throws {
78
+ try validateType()
79
+ try validatePermission(.write)
80
+ try Data(bytes: content.rawPointer, count: content.byteLength).write(to: url)
78
81
  }
79
82
 
80
83
  func text() throws -> String {
@@ -83,6 +86,12 @@ internal final class FileSystemFile: FileSystemPath {
83
86
  return try String(contentsOf: url)
84
87
  }
85
88
 
89
+ func bytes() throws -> Data {
90
+ try validateType()
91
+ try validatePermission(.read)
92
+ return try Data(contentsOf: url)
93
+ }
94
+
86
95
  func base64() throws -> String {
87
96
  try validatePermission(.read)
88
97
  return try Data(contentsOf: url).base64EncodedString()
@@ -1,6 +1,7 @@
1
1
  import Foundation
2
2
  import ExpoModulesCore
3
3
 
4
+ @available(iOS 14, macOS 11, tvOS 14, *)
4
5
  internal final class FileSystemFileHandle: SharedRef<FileHandle> {
5
6
  let file: FileSystemFile
6
7
  let handle: FileHandle
@@ -2,6 +2,7 @@
2
2
 
3
3
  import ExpoModulesCore
4
4
 
5
+ @available(iOS 14, macOS 11, tvOS 14, *)
5
6
  public final class FileSystemNextModule: Module {
6
7
  public func definition() -> ModuleDefinition {
7
8
  Name("FileSystemNext")
@@ -72,6 +73,10 @@ public final class FileSystemNextModule: Module {
72
73
  return try file.base64()
73
74
  }
74
75
 
76
+ Function("bytes") { file in
77
+ return try file.bytes()
78
+ }
79
+
75
80
  Function("open") { file in
76
81
  return try FileSystemFileHandle(file: file)
77
82
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-file-system",
3
- "version": "18.0.3",
3
+ "version": "18.0.5",
4
4
  "description": "Provides access to the local file system on the device.",
5
5
  "main": "src/index.ts",
6
6
  "types": "build/index.d.ts",
@@ -45,5 +45,5 @@
45
45
  "dependencies": {
46
46
  "web-streams-polyfill": "^3.3.2"
47
47
  },
48
- "gitHead": "c4999f5aa407155a170830a0fa17e3e3ca1fcbee"
48
+ "gitHead": "1faceb8d22bebee4571ef3a2f9578bec33dc26b1"
49
49
  }
@@ -97,11 +97,17 @@ export declare class File {
97
97
  */
98
98
  base64(): string;
99
99
 
100
+ /**
101
+ * Retrieves byte content of the entire file.
102
+ * @returns The contents of the file as a Uint8Array.
103
+ */
104
+ bytes(): Uint8Array;
105
+
100
106
  /**
101
107
  * Writes content to the file.
102
108
  * @param content - The content to write into the file.
103
109
  */
104
- write(content: string): void;
110
+ write(content: string | Uint8Array): void;
105
111
 
106
112
  /**
107
113
  * Deletes a file.