FileManager
extension FileManager
-
Zips the file or directory contents at the specified source URL to the destination URL.
If the item at the source URL is a directory, the directory itself will be represented within the ZIP
Archive. Calling this method with a directory URLfile:///path/directory/will create an archive with adirectory/entry at the root level. You can override this behavior by passingfalseforshouldKeepParent. In that case, the contents of the source directory will be placed at the root of the archive.Throws
Throws an error if the source item does not exist or the destination URL is not writable.Declaration
Swift
public func zipItem(at sourceURL: URL, to destinationURL: URL, shouldKeepParent: Bool = true, compressionMethod: CompressionMethod = .none, progress: Progress? = nil) throwsParameters
sourceURLThe file URL pointing to an existing file or directory.
destinationURLThe file URL that identifies the destination of the zip operation.
shouldKeepParentIndicates that the directory name of a source item should be used as root element within the archive. Default is
true.compressionMethodIndicates the
CompressionMethodthat should be applied. By default,zipItemwill create uncompressed archives.progressA progress object that can be used to track or cancel the zip operation.
-
Unzips the contents at the specified source URL to the destination URL.
Throws
Throws an error if the source item does not exist or the destination URL is not writable.Declaration
Swift
public func unzipItem(at sourceURL: URL, to destinationURL: URL, skipCRC32: Bool = false, progress: Progress? = nil, preferredEncoding: String.Encoding? = nil) throwsParameters
sourceURLThe file URL pointing to an existing ZIP file.
destinationURLThe file URL that identifies the destination directory of the unzip operation.
skipCRC32Optional flag to skip calculation of the CRC32 checksum to improve performance.
progressA progress object that can be used to track or cancel the unzip operation.
preferredEncodingEncoding for entry paths. Overrides the encoding specified in the archive.
FileManager Extension Reference