@capacitor/filesystem 7.0.2-nightly-20250523T150554.0 → 7.1.0-dev.1
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/CapacitorFilesystem.podspec +4 -3
- package/Package.swift +10 -4
- package/README.md +149 -78
- package/android/build.gradle +12 -22
- package/android/src/main/kotlin/com/capacitorjs/plugins/filesystem/FilesystemErrors.kt +101 -0
- package/android/src/main/kotlin/com/capacitorjs/plugins/filesystem/FilesystemMethodOptions.kt +129 -0
- package/android/src/main/kotlin/com/capacitorjs/plugins/filesystem/FilesystemMethodResults.kt +65 -0
- package/android/src/main/kotlin/com/capacitorjs/plugins/filesystem/FilesystemPlugin.kt +412 -0
- package/android/src/main/kotlin/com/capacitorjs/plugins/filesystem/LegacyFilesystemImplementation.kt +169 -0
- package/android/src/main/kotlin/com/capacitorjs/plugins/filesystem/PluginResultExtensions.kt +25 -0
- package/dist/docs.json +227 -145
- package/dist/esm/definitions.d.ts +102 -64
- package/dist/esm/definitions.js +25 -3
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/index.js +3 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/web.d.ts +3 -1
- package/dist/esm/web.js +10 -10
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +40 -14
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +41 -16
- package/dist/plugin.js.map +1 -1
- package/ios/Sources/FilesystemPlugin/CAPPluginCall+Accelerators.swift +73 -0
- package/ios/Sources/FilesystemPlugin/FilesystemConstants.swift +61 -0
- package/ios/Sources/FilesystemPlugin/FilesystemError.swift +57 -0
- package/ios/Sources/FilesystemPlugin/FilesystemLocationResolver.swift +39 -0
- package/ios/Sources/FilesystemPlugin/FilesystemOperation.swift +24 -0
- package/ios/Sources/FilesystemPlugin/FilesystemOperationExecutor.swift +116 -0
- package/ios/Sources/FilesystemPlugin/FilesystemPlugin.swift +103 -264
- package/ios/Sources/FilesystemPlugin/IONFileStructures+Converters.swift +60 -0
- package/ios/Sources/FilesystemPlugin/{Filesystem.swift → LegacyFilesystemImplementation.swift} +18 -179
- package/package.json +28 -24
- package/LICENSE +0 -23
- package/android/src/main/java/com/capacitorjs/plugins/filesystem/Filesystem.java +0 -414
- package/android/src/main/java/com/capacitorjs/plugins/filesystem/FilesystemPlugin.java +0 -551
- package/android/src/main/java/com/capacitorjs/plugins/filesystem/exceptions/CopyFailedException.java +0 -16
- package/android/src/main/java/com/capacitorjs/plugins/filesystem/exceptions/DirectoryExistsException.java +0 -16
- package/android/src/main/java/com/capacitorjs/plugins/filesystem/exceptions/DirectoryNotFoundException.java +0 -16
package/ios/Sources/FilesystemPlugin/{Filesystem.swift → LegacyFilesystemImplementation.swift}
RENAMED
|
@@ -1,188 +1,10 @@
|
|
|
1
1
|
import Foundation
|
|
2
2
|
import Capacitor
|
|
3
3
|
|
|
4
|
-
@objc public class
|
|
5
|
-
|
|
6
|
-
public enum FilesystemError: LocalizedError {
|
|
7
|
-
case noParentFolder, noSave, failEncode, noAppend, notEmpty
|
|
8
|
-
|
|
9
|
-
public var errorDescription: String? {
|
|
10
|
-
switch self {
|
|
11
|
-
case .noParentFolder:
|
|
12
|
-
return "Parent folder doesn't exist"
|
|
13
|
-
case .noSave:
|
|
14
|
-
return "Unable to save file"
|
|
15
|
-
case .failEncode:
|
|
16
|
-
return "Unable to encode data to utf-8"
|
|
17
|
-
case .noAppend:
|
|
18
|
-
return "Unable to append file"
|
|
19
|
-
case .notEmpty:
|
|
20
|
-
return "Folder is not empty"
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
4
|
+
@objc public class LegacyFilesystemImplementation: NSObject {
|
|
24
5
|
|
|
25
6
|
public typealias ProgressEmitter = (_ bytes: Int64, _ contentLength: Int64) -> Void
|
|
26
7
|
|
|
27
|
-
public func readFile(at fileUrl: URL, with encoding: String?) throws -> String {
|
|
28
|
-
fileUrl.startAccessingSecurityScopedResource()
|
|
29
|
-
if encoding != nil {
|
|
30
|
-
let data = try String(contentsOf: fileUrl, encoding: .utf8)
|
|
31
|
-
fileUrl.stopAccessingSecurityScopedResource()
|
|
32
|
-
return data
|
|
33
|
-
} else {
|
|
34
|
-
let data = try Data(contentsOf: fileUrl)
|
|
35
|
-
fileUrl.stopAccessingSecurityScopedResource()
|
|
36
|
-
return data.base64EncodedString()
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
public func writeFile(at fileUrl: URL, with data: String, recursive: Bool, with encoding: String?) throws -> String {
|
|
41
|
-
if !FileManager.default.fileExists(atPath: fileUrl.deletingLastPathComponent().path) {
|
|
42
|
-
if recursive {
|
|
43
|
-
try FileManager.default.createDirectory(at: fileUrl.deletingLastPathComponent(), withIntermediateDirectories: recursive, attributes: nil)
|
|
44
|
-
} else {
|
|
45
|
-
throw FilesystemError.noParentFolder
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
if encoding != nil {
|
|
49
|
-
try data.write(to: fileUrl, atomically: false, encoding: .utf8)
|
|
50
|
-
} else {
|
|
51
|
-
if let base64Data = Data.capacitor.data(base64EncodedOrDataUrl: data) {
|
|
52
|
-
try base64Data.write(to: fileUrl)
|
|
53
|
-
} else {
|
|
54
|
-
throw FilesystemError.noSave
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return fileUrl.absoluteString
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
@objc public func appendFile(at fileUrl: URL, with data: String, recursive: Bool, with encoding: String?) throws {
|
|
61
|
-
if FileManager.default.fileExists(atPath: fileUrl.path) {
|
|
62
|
-
let fileHandle = try FileHandle.init(forWritingTo: fileUrl)
|
|
63
|
-
var writeData: Data?
|
|
64
|
-
if encoding != nil {
|
|
65
|
-
guard let userData = data.data(using: .utf8) else {
|
|
66
|
-
throw FilesystemError.failEncode
|
|
67
|
-
}
|
|
68
|
-
writeData = userData
|
|
69
|
-
} else {
|
|
70
|
-
if let base64Data = Data.capacitor.data(base64EncodedOrDataUrl: data) {
|
|
71
|
-
writeData = base64Data
|
|
72
|
-
} else {
|
|
73
|
-
throw FilesystemError.noAppend
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
defer {
|
|
77
|
-
fileHandle.closeFile()
|
|
78
|
-
}
|
|
79
|
-
fileHandle.seekToEndOfFile()
|
|
80
|
-
fileHandle.write(writeData!)
|
|
81
|
-
} else {
|
|
82
|
-
_ = try writeFile(at: fileUrl, with: data, recursive: recursive, with: encoding)
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
@objc func deleteFile(at fileUrl: URL) throws {
|
|
87
|
-
if FileManager.default.fileExists(atPath: fileUrl.path) {
|
|
88
|
-
try FileManager.default.removeItem(atPath: fileUrl.path)
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
@objc public func mkdir(at fileUrl: URL, recursive: Bool) throws {
|
|
93
|
-
try FileManager.default.createDirectory(at: fileUrl, withIntermediateDirectories: recursive, attributes: nil)
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
@objc public func rmdir(at fileUrl: URL, recursive: Bool) throws {
|
|
97
|
-
let directoryContents = try FileManager.default.contentsOfDirectory(at: fileUrl, includingPropertiesForKeys: nil, options: [])
|
|
98
|
-
if directoryContents.count != 0 && !recursive {
|
|
99
|
-
throw FilesystemError.notEmpty
|
|
100
|
-
}
|
|
101
|
-
try FileManager.default.removeItem(at: fileUrl)
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
public func readdir(at fileUrl: URL) throws -> [URL] {
|
|
105
|
-
return try FileManager.default.contentsOfDirectory(at: fileUrl, includingPropertiesForKeys: nil, options: [])
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
func stat(at fileUrl: URL) throws -> [FileAttributeKey: Any] {
|
|
109
|
-
return try FileManager.default.attributesOfItem(atPath: fileUrl.path)
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
func getType(from attr: [FileAttributeKey: Any]) -> String {
|
|
113
|
-
let fileType = attr[.type] as? String ?? ""
|
|
114
|
-
if fileType == "NSFileTypeDirectory" {
|
|
115
|
-
return "directory"
|
|
116
|
-
} else {
|
|
117
|
-
return "file"
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
@objc public func rename(at srcURL: URL, to dstURL: URL) throws {
|
|
122
|
-
try _copy(at: srcURL, to: dstURL, doRename: true)
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
@objc public func copy(at srcURL: URL, to dstURL: URL) throws {
|
|
126
|
-
try _copy(at: srcURL, to: dstURL, doRename: false)
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Copy or rename a file or directory.
|
|
131
|
-
*/
|
|
132
|
-
private func _copy(at srcURL: URL, to dstURL: URL, doRename: Bool) throws {
|
|
133
|
-
if srcURL == dstURL {
|
|
134
|
-
return
|
|
135
|
-
}
|
|
136
|
-
var isDir: ObjCBool = false
|
|
137
|
-
if FileManager.default.fileExists(atPath: dstURL.path, isDirectory: &isDir) {
|
|
138
|
-
if !isDir.boolValue {
|
|
139
|
-
try? FileManager.default.removeItem(at: dstURL)
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
if doRename {
|
|
144
|
-
try FileManager.default.moveItem(at: srcURL, to: dstURL)
|
|
145
|
-
} else {
|
|
146
|
-
try FileManager.default.copyItem(at: srcURL, to: dstURL)
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Get the SearchPathDirectory corresponding to the JS string
|
|
153
|
-
*/
|
|
154
|
-
public func getDirectory(directory: String?) -> FileManager.SearchPathDirectory? {
|
|
155
|
-
if let directory = directory {
|
|
156
|
-
switch directory {
|
|
157
|
-
case "CACHE":
|
|
158
|
-
return .cachesDirectory
|
|
159
|
-
case "LIBRARY":
|
|
160
|
-
return .libraryDirectory
|
|
161
|
-
default:
|
|
162
|
-
return .documentDirectory
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
return nil
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* Get the URL for this file, supporting file:// paths and
|
|
170
|
-
* files with directory mappings.
|
|
171
|
-
*/
|
|
172
|
-
@objc public func getFileUrl(at path: String, in directory: String?) -> URL? {
|
|
173
|
-
if let directory = getDirectory(directory: directory) {
|
|
174
|
-
guard let dir = FileManager.default.urls(for: directory, in: .userDomainMask).first else {
|
|
175
|
-
return nil
|
|
176
|
-
}
|
|
177
|
-
if !path.isEmpty {
|
|
178
|
-
return dir.appendingPathComponent(path)
|
|
179
|
-
}
|
|
180
|
-
return dir
|
|
181
|
-
} else {
|
|
182
|
-
return URL(string: path)
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
8
|
// swiftlint:disable function_body_length
|
|
187
9
|
@objc public func downloadFile(call: CAPPluginCall, emitter: @escaping ProgressEmitter, config: InstanceConfiguration?) throws {
|
|
188
10
|
let directory = call.getString("directory", "DOCUMENTS")
|
|
@@ -341,4 +163,21 @@ import Capacitor
|
|
|
341
163
|
task.resume()
|
|
342
164
|
}
|
|
343
165
|
// swiftlint:enable function_body_length
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Get the SearchPathDirectory corresponding to the JS string
|
|
169
|
+
*/
|
|
170
|
+
private func getDirectory(directory: String?) -> FileManager.SearchPathDirectory? {
|
|
171
|
+
if let directory = directory {
|
|
172
|
+
switch directory {
|
|
173
|
+
case "CACHE":
|
|
174
|
+
return .cachesDirectory
|
|
175
|
+
case "LIBRARY":
|
|
176
|
+
return .libraryDirectory
|
|
177
|
+
default:
|
|
178
|
+
return .documentDirectory
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return nil
|
|
182
|
+
}
|
|
344
183
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capacitor/filesystem",
|
|
3
|
-
"version": "7.0
|
|
3
|
+
"version": "7.1.0-dev.1",
|
|
4
4
|
"description": "The Filesystem API provides a NodeJS-like API for working with files on the device.",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -15,14 +15,14 @@
|
|
|
15
15
|
"Package.swift",
|
|
16
16
|
"CapacitorFilesystem.podspec"
|
|
17
17
|
],
|
|
18
|
-
"author": "
|
|
18
|
+
"author": "Outsystems",
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"repository": {
|
|
21
21
|
"type": "git",
|
|
22
|
-
"url": "https://github.com/ionic-team/capacitor-
|
|
22
|
+
"url": "https://github.com/ionic-team/capacitor-filesystem.git"
|
|
23
23
|
},
|
|
24
24
|
"bugs": {
|
|
25
|
-
"url": "https://github.com/ionic-team/capacitor-
|
|
25
|
+
"url": "https://github.com/ionic-team/capacitor-filesystem/issues"
|
|
26
26
|
},
|
|
27
27
|
"keywords": [
|
|
28
28
|
"capacitor",
|
|
@@ -31,36 +31,44 @@
|
|
|
31
31
|
],
|
|
32
32
|
"scripts": {
|
|
33
33
|
"verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
|
|
34
|
-
"verify:ios": "xcodebuild
|
|
34
|
+
"verify:ios": "xcodebuild -scheme FilesystemCapacitor -destination generic/platform=iOS",
|
|
35
35
|
"verify:android": "cd android && ./gradlew clean build test && cd ..",
|
|
36
36
|
"verify:web": "npm run build",
|
|
37
37
|
"lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
|
|
38
38
|
"fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
|
|
39
39
|
"eslint": "eslint . --ext ts",
|
|
40
|
-
"prettier": "prettier \"**/*.{css,html,ts,js,java}\"",
|
|
40
|
+
"prettier": "prettier \"**/*.{css,html,ts,js,java}\" --plugin=prettier-plugin-java",
|
|
41
41
|
"swiftlint": "node-swiftlint",
|
|
42
42
|
"docgen": "docgen --api FilesystemPlugin --output-readme README.md --output-json dist/docs.json",
|
|
43
43
|
"build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
|
|
44
44
|
"clean": "rimraf ./dist",
|
|
45
45
|
"watch": "tsc --watch",
|
|
46
|
-
"prepublishOnly": "npm run build"
|
|
47
|
-
|
|
46
|
+
"prepublishOnly": "npm run build"
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"@capacitor/synapse": "^1.0.1"
|
|
48
50
|
},
|
|
49
51
|
"devDependencies": {
|
|
50
|
-
"@capacitor/android": "
|
|
51
|
-
"@capacitor/core": "
|
|
52
|
-
"@capacitor/docgen": "0.2.2",
|
|
53
|
-
"@capacitor/ios": "
|
|
52
|
+
"@capacitor/android": "7.0.1",
|
|
53
|
+
"@capacitor/core": "7.0.1",
|
|
54
|
+
"@capacitor/docgen": "^0.2.2",
|
|
55
|
+
"@capacitor/ios": "7.0.1",
|
|
54
56
|
"@ionic/eslint-config": "^0.4.0",
|
|
55
|
-
"@ionic/prettier-config": "
|
|
56
|
-
"@ionic/swiftlint-config": "^
|
|
57
|
+
"@ionic/prettier-config": "^4.0.0",
|
|
58
|
+
"@ionic/swiftlint-config": "^2.0.0",
|
|
59
|
+
"@semantic-release/changelog": "^6.0.3",
|
|
60
|
+
"@semantic-release/git": "^10.0.1",
|
|
61
|
+
"@semantic-release/github": "^11.0.1",
|
|
62
|
+
"@semantic-release/npm": "^12.0.1",
|
|
63
|
+
"@types/node": "^20.14.8",
|
|
57
64
|
"eslint": "^8.57.0",
|
|
58
|
-
"prettier": "
|
|
59
|
-
"prettier-plugin-java": "
|
|
65
|
+
"prettier": "^3.3.3",
|
|
66
|
+
"prettier-plugin-java": "^2.6.4",
|
|
60
67
|
"rimraf": "^6.0.1",
|
|
61
|
-
"rollup": "^
|
|
62
|
-
"
|
|
63
|
-
"
|
|
68
|
+
"rollup": "^2.78.1",
|
|
69
|
+
"semantic-release": "^24.0.0",
|
|
70
|
+
"swiftlint": "^2.0.0",
|
|
71
|
+
"typescript": "~5.4.5"
|
|
64
72
|
},
|
|
65
73
|
"peerDependencies": {
|
|
66
74
|
"@capacitor/core": ">=7.0.0"
|
|
@@ -77,9 +85,5 @@
|
|
|
77
85
|
"android": {
|
|
78
86
|
"src": "android"
|
|
79
87
|
}
|
|
80
|
-
}
|
|
81
|
-
"publishConfig": {
|
|
82
|
-
"access": "public"
|
|
83
|
-
},
|
|
84
|
-
"gitHead": "10cf0ed6c943b3e7b35daeea20dfdbbce37206b2"
|
|
88
|
+
}
|
|
85
89
|
}
|
package/LICENSE
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
Copyright 2020-present Ionic
|
|
2
|
-
https://ionic.io
|
|
3
|
-
|
|
4
|
-
MIT License
|
|
5
|
-
|
|
6
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
|
7
|
-
a copy of this software and associated documentation files (the
|
|
8
|
-
"Software"), to deal in the Software without restriction, including
|
|
9
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
|
10
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
|
11
|
-
permit persons to whom the Software is furnished to do so, subject to
|
|
12
|
-
the following conditions:
|
|
13
|
-
|
|
14
|
-
The above copyright notice and this permission notice shall be
|
|
15
|
-
included in all copies or substantial portions of the Software.
|
|
16
|
-
|
|
17
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
18
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
19
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
20
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
21
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
22
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
23
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|