1
Fork 0
This repository has been archived on 2025-04-12. You can view files and clone it, but cannot push or open issues or pull requests.
silica-viewer/ProcreateViewer/Document.swift

40 lines
1.1 KiB
Swift
Raw Normal View History

2020-03-10 14:23:54 -04:00
import Cocoa
import ZIPFoundation
class Document: NSDocument {
var image: NSImage?
override init() {
super.init()
}
override func makeWindowControllers() {
let storyboard = NSStoryboard(name: NSStoryboard.Name("Main"), bundle: nil)
let windowController = storyboard.instantiateController(withIdentifier: NSStoryboard.SceneIdentifier("Document Window Controller")) as! NSWindowController
self.addWindowController(windowController)
}
override func read(from data: Data, ofType typeName: String) throws {
guard let archive = Archive(data: data, accessMode: Archive.AccessMode.read) else {
return
}
guard let entry = archive["QuickLook/Thumbnail.png"] else {
return
}
var top_data = Data()
do {
try archive.extract(entry, consumer: { (d) in
top_data.append(d)
})
} catch {
Swift.print("Extracting entry from archive failed with error:\(error)")
}
image = NSImage(data: top_data)
}
}