https://github.com/weichsel/ZIPFoundation#accessing-individual-entries
우선 iOS에서 파일 zip/unzip에 가장 인기있는 library가 2가지 있는다
https://github.com/marmelroy/Zip
https://github.com/ZipArchive/ZipArchive
두 라이브러리 모두 minizip이라는 오픈소스 라이브러리를 기반으로 하고있다.
처음에는 저 두 라이브러라를 활용해 볼 생각이었지만 적용후 오류를 발견하게 되었따.
내가 진행하는프로젝트 라이브러리중 minizip을 사용하는 라이브러리가 있었고 파일을 압축할때
다른 버전의 minizip 2가지를 사용하게 되었고 openZip메소드에서 충돌이 발생해 EXC_BAD_ACCESS
앱이 죽는 현상을 경험 하였음.
ZIPFoundation은 minizip이라는 c기반의 라이브러리를 사용하지 않고 99.6퍼센트 swift코드로 작성된 라이브러리이다.
//SAMPLE CODE
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)")
}
파일 path를 URL객체로 초기화 하기 위해서는
URL(string:) 메소드를 사용하면 안됨.
URL(fileURLwithPath:) 메소드를 사용해야 함.