expo-file-system 18.0.4 → 18.0.6

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.6 — 2024-12-16
14
+
15
+ ### 🎉 New features
16
+
17
+ - [next] Add blob support and `.blob()` function. ([#33152](https://github.com/expo/expo/pull/33152) by [@aleqsio](https://github.com/aleqsio))
18
+
19
+ ## 18.0.5 — 2024-12-10
20
+
21
+ ### 🐛 Bug fixes
22
+
23
+ - [macOS][next]: Add availability checks ([#33504](https://github.com/expo/expo/pull/33504) by [@hassankhan](https://github.com/hassankhan))
24
+
13
25
  ## 18.0.4 — 2024-11-19
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.4'
4
+ version = '18.0.6'
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.4"
17
+ versionName "18.0.6"
18
18
  }
19
19
  }
20
20
 
@@ -2,6 +2,7 @@ package expo.modules.filesystem.next
2
2
 
3
3
  import android.net.Uri
4
4
  import android.util.Base64
5
+ import android.webkit.MimeTypeMap
5
6
  import expo.modules.interfaces.filesystem.Permission
6
7
  import expo.modules.kotlin.apifeatures.EitherType
7
8
  import expo.modules.kotlin.typedarray.TypedArray
@@ -95,4 +96,9 @@ class FileSystemFile(file: File) : FileSystemPath(file) {
95
96
  null
96
97
  }
97
98
  }
99
+
100
+ val type: String? get() {
101
+ return MimeTypeMap.getFileExtensionFromUrl(file.path)
102
+ ?.run { MimeTypeMap.getSingleton().getMimeTypeFromExtension(lowercase()) }
103
+ }
98
104
  }
@@ -138,6 +138,10 @@ class FileSystemNextModule : Module() {
138
138
  }
139
139
  }
140
140
 
141
+ Property("type") { file ->
142
+ file.type
143
+ }
144
+
141
145
  Function("open") { file: FileSystemFile ->
142
146
  FileSystemFileHandle(file)
143
147
  }
@@ -144,6 +144,10 @@ export declare class File {
144
144
  * An md5 hash of the file. Null if the file does not exist or it cannot be read.
145
145
  */
146
146
  md5: string | null;
147
+ /**
148
+ * A mime type of the file. Null if the file does not exist or it cannot be read.
149
+ */
150
+ type: string | null;
147
151
  }
148
152
  export declare class FileHandle {
149
153
  close(): void;
@@ -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;IACH,IAAI,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,EAAE;CAC7B;AAED;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,IAAI;IACvB;;;;OAIG;gBACS,GAAG,IAAI,EAAE,C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,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;IAEnB;;OAEG;IACH,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CACrB;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"}
@@ -12,6 +12,19 @@ export declare class Paths extends PathUtilities {
12
12
  static get document(): Directory;
13
13
  static get appleSharedContainers(): Record<string, Directory>;
14
14
  }
15
+ export declare class FileBlob extends Blob {
16
+ file: File;
17
+ key: string;
18
+ constructor(file: File);
19
+ get size(): number;
20
+ get name(): string;
21
+ get type(): string;
22
+ arrayBuffer(): Promise<ArrayBuffer>;
23
+ text(): Promise<string>;
24
+ bytes(): Promise<Uint8Array>;
25
+ stream(): ReadableStream<Uint8Array>;
26
+ slice(start?: number, end?: number, contentType?: string): Blob;
27
+ }
15
28
  export declare class File extends ExpoFileSystem.FileSystemFile {
16
29
  /**
17
30
  * Creates an instance of a file.
@@ -22,6 +35,7 @@ export declare class File extends ExpoFileSystem.FileSystemFile {
22
35
  * ```
23
36
  */
24
37
  constructor(...uris: (string | File | Directory)[]);
38
+ blob(): Blob;
25
39
  get parentDirectory(): Directory;
26
40
  /**
27
41
  * File extension.
@@ -1 +1 @@
1
- {"version":3,"file":"FileSystem.d.ts","sourceRoot":"","sources":["../../src/next/FileSystem.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtE,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGhD,qBAAa,KAAM,SAAQ,aAAa;IACtC;;OAEG;IACH,MAAM,KAAK,KAAK,cAEf;IAED;;OAEG;IACH,MAAM,KAAK,QAAQ,cAElB;IACD,MAAM,KAAK,qBAAqB,8BAO/B;CACF;AAED,qBAAa,IAAK,SAAQ,cAAc,CAAC,cAAc;IACrD;;;;;;;OAOG;gBACS,GAAG,IAAI,EAAE,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,EAAE;IAQlD,IAAI,eAAe,cAElB;IAED;;;OAGG;IACH,IAAI,SAAS,WAEZ;IAED;;OAEG;IACH,IAAI,IAAI,WAEP;IAED,cAAc;IAId,cAAc;CAGf;AAQD;;;;GAIG;AACH,qBAAa,SAAU,SAAQ,cAAc,CAAC,mBAAmB;IAC/D;;;;;;;OAOG;gBACS,GAAG,IAAI,EAAE,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,EAAE;IAQlD,IAAI,eAAe,cAElB;IAED;;;;OAIG;IACH,IAAI,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,EAAE;IAO5B;;OAEG;IACH,IAAI,IAAI,WAEP;CACF"}
1
+ {"version":3,"file":"FileSystem.d.ts","sourceRoot":"","sources":["../../src/next/FileSystem.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtE,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGhD,qBAAa,KAAM,SAAQ,aAAa;IACtC;;OAEG;IACH,MAAM,K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: 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
  }
@@ -1,6 +1,7 @@
1
1
  import Foundation
2
2
  import ExpoModulesCore
3
3
  import CryptoKit
4
+ import UniformTypeIdentifiers
4
5
 
5
6
  internal final class FileSystemFile: FileSystemPath {
6
7
  init(url: URL) {
@@ -67,6 +68,15 @@ internal final class FileSystemFile: FileSystemPath {
67
68
  }
68
69
  }
69
70
 
71
+ var type: String? {
72
+ let pathExtension = url.pathExtension
73
+ if let utType = UTType(filenameExtension: pathExtension),
74
+ let mimeType = utType.preferredMIMEType {
75
+ return mimeType
76
+ }
77
+ return nil
78
+ }
79
+
70
80
  func write(_ content: String) throws {
71
81
  try validateType()
72
82
  try validatePermission(.write)
@@ -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")
@@ -97,6 +98,10 @@ public final class FileSystemNextModule: Module {
97
98
  try? file.md5
98
99
  }
99
100
 
101
+ Property("type") { file in
102
+ file.type
103
+ }
104
+
100
105
  Function("delete") { file in
101
106
  try file.delete()
102
107
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-file-system",
3
- "version": "18.0.4",
3
+ "version": "18.0.6",
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": "128718d43bac2eaed764b3551469b95400f2363e"
48
+ "gitHead": "637acf537a92ac6209bfced71e097ba736b43fef"
49
49
  }
@@ -166,6 +166,11 @@ export declare class File {
166
166
  * An md5 hash of the file. Null if the file does not exist or it cannot be read.
167
167
  */
168
168
  md5: string | null;
169
+
170
+ /**
171
+ * A mime type of the file. Null if the file does not exist or it cannot be read.
172
+ */
173
+ type: string | null;
169
174
  }
170
175
 
171
176
  export declare class FileHandle {
@@ -28,6 +28,48 @@ export class Paths extends PathUtilities {
28
28
  }
29
29
  }
30
30
 
31
+ export class FileBlob extends Blob {
32
+ file: File;
33
+ key: string = 'FileBlob';
34
+
35
+ constructor(file: File) {
36
+ super();
37
+ this.file = file;
38
+ }
39
+
40
+ get size(): number {
41
+ return this.file.size ?? 0;
42
+ }
43
+
44
+ get name(): string {
45
+ return this.file.name;
46
+ }
47
+
48
+ get type(): string {
49
+ return this.file.type ?? '';
50
+ }
51
+
52
+ async arrayBuffer(): Promise<ArrayBuffer> {
53
+ return this.file.bytes().buffer;
54
+ }
55
+
56
+ async text(): Promise<string> {
57
+ return this.file.text();
58
+ }
59
+
60
+ async bytes(): Promise<Uint8Array> {
61
+ return this.file.bytes();
62
+ }
63
+
64
+ stream(): ReadableStream<Uint8Array> {
65
+ return this.file.readableStream();
66
+ }
67
+
68
+ slice(start?: number, end?: number, contentType?: string): Blob {
69
+ return new Blob([this.file.bytes().slice(start, end)], { type: contentType });
70
+ }
71
+ }
72
+
31
73
  export class File extends ExpoFileSystem.FileSystemFile {
32
74
  /**
33
75
  * Creates an instance of a file.
@@ -42,6 +84,13 @@ export class File extends ExpoFileSystem.FileSystemFile {
42
84
  this.validatePath();
43
85
  }
44
86
 
87
+ /*
88
+ * Returns the file as a Blob. The blob can be used in `@expo/fetch` to send files over network and for other uses.
89
+ */
90
+ blob(): Blob {
91
+ return new FileBlob(this);
92
+ }
93
+
45
94
  /*
46
95
  * Directory containing the file.
47
96
  */