Skip to content

Instantly share code, notes, and snippets.

@InfRandomness
Created June 22, 2022 11:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save InfRandomness/b85767c1db780cf6bd9658d7c91a5db0 to your computer and use it in GitHub Desktop.
Save InfRandomness/b85767c1db780cf6bd9658d7c91a5db0 to your computer and use it in GitHub Desktop.
ZIPFoundation basic code
import Foundation
import ZIPFoundation
let fileManager = FileManager()
let currentWorkingPath = fileManager.currentDirectoryPath
var sourceURL = URL(fileURLWithPath: currentWorkingPath)
sourceURL.appendPathComponent("file.txt")
var destinationURL = URL(fileURLWithPath: currentWorkingPath)
destinationURL.appendPathComponent("archive.zip")
do {
try fileManager.zipItem(at: sourceURL, to: destinationURL)
} catch {
print("Creation of ZIP archive failed with error:\(error)")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment