Add export function
This commit is contained in:
@@ -2,6 +2,7 @@ import Foundation
|
||||
import Combine
|
||||
import BinaryCodable
|
||||
import SwiftUI
|
||||
import ZIPFoundation
|
||||
|
||||
final class PersistentStorage: ObservableObject {
|
||||
|
||||
@@ -353,6 +354,34 @@ final class PersistentStorage: ObservableObject {
|
||||
defer { updateTransferCount() }
|
||||
return save(data: data, date: date, in: "transfers")
|
||||
}
|
||||
|
||||
// MARK: Export
|
||||
|
||||
private var zipArchive: URL {
|
||||
FileManager.default.temporaryDirectory.appendingPathComponent("data.zip")
|
||||
}
|
||||
|
||||
func createZip() throws -> URL {
|
||||
// Define the destination zip file path
|
||||
let archive = zipArchive
|
||||
|
||||
// Create the zip file
|
||||
try FileManager.default.zipItem(
|
||||
at: PersistentStorage.documentDirectory,
|
||||
to: archive,
|
||||
shouldKeepParent: false,
|
||||
compressionMethod: .deflate)
|
||||
return archive
|
||||
}
|
||||
|
||||
func removeZipArchive() throws {
|
||||
let archive = zipArchive
|
||||
// Remove existing zip file if it exists
|
||||
if FileManager.default.fileExists(atPath: archive.path) {
|
||||
print("Removing archive file")
|
||||
try FileManager.default.removeItem(at: archive)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private extension Array where Element == TemperatureMeasurement {
|
||||
|
Reference in New Issue
Block a user