I have to preview zip files using Document Interaction Controller, but zip files containing video content should not be previewed. Is there a way to check zip file containing video content using swift?
Asked
Active
Viewed 302 times
1
-
Well presumably you'd need to unzip it. Otherwise how would you know what's in it? – matt Jun 22 '21 at 08:48
1 Answers
3
There's a 3rd party library called ZIPFoundation that makes it convenient to traverse zip entries.
- Install
pod 'ZipFoundation'
in your project. - Copy / paste below helper code in your project.
import Foundation
import ZIPFoundation
extension String {
var pathExtension: String {
URL(fileURLWithPath: self).pathExtension
}
}
extension Archive {
var containsVideo: Bool {
let videoTypes: [String] = ["MOV", "MP4", "AVI"]
for entry in self where entry.type == .file {
let type = entry.path.pathExtension.uppercased()
if videoTypes.contains(type) {
return true
}
}
return false
}
}
From the call site, you can use it like following -
if let zipURL = Bundle.main.url(forResource: "Test", withExtension: "zip"),
let arhive = Archive(url: zipURL, accessMode: .read) {
print(arhive.containsVideo)
}

Tarun Tyagi
- 9,364
- 2
- 17
- 30