Skip to content

Commit

Permalink
Allow writing empty files (#1057)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile committed Dec 13, 2018
1 parent d73eb27 commit 8d9a596
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions ios/Capacitor/Capacitor/Plugins/Filesystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public class CAPFilesystemPlugin : CAPPlugin {
return
}

guard let data = call.get("data", String.self), !data.isEmpty else {
guard let data = call.get("data", String.self) else {
handleError(call, "Data must be provided and must be a string.")
return
}
Expand All @@ -108,7 +108,11 @@ public class CAPFilesystemPlugin : CAPPlugin {
try data.write(to: fileUrl, atomically: false, encoding: .utf8)
} else {
let dataParts = data.split(separator: ",")
if let base64Data = Data(base64Encoded: String(dataParts.last!)) {
var cleanData = data
if dataParts.count > 0 {
cleanData = String(dataParts.last!)
}
if let base64Data = Data(base64Encoded: cleanData) {
try base64Data.write(to: fileUrl)
} else {
handleError(call, "Unable to save file")
Expand Down

0 comments on commit 8d9a596

Please sign in to comment.