summaryrefslogtreecommitdiff
path: root/Sora/Data/JSONFileDocument.swift
blob: bc41616a66f20f1363a4025d0b53a4dd9d6917b8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import SwiftUI
import UniformTypeIdentifiers

struct JSONFileDocument: FileDocument {
  static var readableContentTypes: [UTType] { [.json] }

  var data: Data

  init(_ data: Data) throws {
    self.data = data
  }

  init(configuration: ReadConfiguration) throws {
    guard let data = configuration.file.regularFileContents else {
      throw CocoaError(.fileReadCorruptFile)
    }

    self.data = data
  }

  func fileWrapper(
    configuration: WriteConfiguration  // swiftlint:disable:this unused_parameter
  ) throws -> FileWrapper {
    FileWrapper(regularFileWithContents: data)
  }
}