Skip to content

Commit cfba89d

Browse files
committed
[feat]: avoid rewrite
1 parent 790faa9 commit cfba89d

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Sources/ScriptToolkit/NSImageExtension.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,14 @@ public extension NSImage {
6262
/// Saves the PNG representation of the current image to the HD.
6363
///
6464
/// - parameter url: The location url to which to write the png file.
65-
func savePNGRepresentationToURL(url: URL) throws {
65+
func savePNGRepresentationToURL(url: URL, onlyChange: Bool) throws {
6666
if let png = self.PNGRepresentation {
67+
if let originalData = try? Data(contentsOf: url) {
68+
if onlyChange && (png == originalData) {
69+
return
70+
}
71+
}
72+
6773
try png.write(to: url, options: .atomicWrite)
6874
}
6975
}

0 commit comments

Comments
 (0)