Commit 03610f11 by Sarkizz

添加压缩和解压

parent 2cb05fe1
...@@ -51,7 +51,7 @@ Pod::Spec.new do |s| ...@@ -51,7 +51,7 @@ Pod::Spec.new do |s|
s.source_files = "MRFramework/MRFramework/FoundationManagers/Namespace/*.swift" s.source_files = "MRFramework/MRFramework/FoundationManagers/Namespace/*.swift"
end end
s.subspec 'Parser' do |pa| s.subspec 'Parser' do |pa|
s.source_files = "MRFramework/MRFramework/FoundationManagers/Parser/*.swift" pa.source_files = "MRFramework/MRFramework/FoundationManagers/Parser/*.swift"
end end
end end
...@@ -83,5 +83,6 @@ Pod::Spec.new do |s| ...@@ -83,5 +83,6 @@ Pod::Spec.new do |s|
s.dependency "SnapKit", "4.2.0" s.dependency "SnapKit", "4.2.0"
s.dependency "KeychainAccess", "3.2.0" s.dependency "KeychainAccess", "3.2.0"
s.dependency 'Zip'
end end
...@@ -414,7 +414,6 @@ ...@@ -414,7 +414,6 @@
A7B8E122230B9DD500999DF2 /* Sources */, A7B8E122230B9DD500999DF2 /* Sources */,
A7B8E123230B9DD500999DF2 /* Frameworks */, A7B8E123230B9DD500999DF2 /* Frameworks */,
A7B8E124230B9DD500999DF2 /* Resources */, A7B8E124230B9DD500999DF2 /* Resources */,
6319323C27091693F917E5AD /* [CP] Embed Pods Frameworks */,
); );
buildRules = ( buildRules = (
); );
...@@ -500,26 +499,6 @@ ...@@ -500,26 +499,6 @@
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0; showEnvVarsInLog = 0;
}; };
6319323C27091693F917E5AD /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
"${SRCROOT}/Pods/Target Support Files/Pods-MRFrameworkTests/Pods-MRFrameworkTests-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/KeychainAccess/KeychainAccess.framework",
"${BUILT_PRODUCTS_DIR}/SnapKit/SnapKit.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/KeychainAccess.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SnapKit.framework",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-MRFrameworkTests/Pods-MRFrameworkTests-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
C3DA4B7407F949C2F365A9A4 /* [CP] Check Pods Manifest.lock */ = { C3DA4B7407F949C2F365A9A4 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase; isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
// //
import Foundation import Foundation
import Zip
public enum MRFilesErrorCode: Int { public enum MRFilesErrorCode: Int {
case notExists = -1 case notExists = -1
...@@ -17,6 +18,7 @@ public enum MRFilesErrorCode: Int { ...@@ -17,6 +18,7 @@ public enum MRFilesErrorCode: Int {
case moveError = -6 case moveError = -6
case linkError = -7 case linkError = -7
case readError = -8 case readError = -8
case unzipError = -9
} }
/** /**
...@@ -339,6 +341,44 @@ extension MRFiles { ...@@ -339,6 +341,44 @@ extension MRFiles {
} }
} }
extension MRFiles {
public class func urlCanUnzip(_ url: URL) -> Bool {
return Zip.isValidFileExtension(url.pathExtension)
}
public class func zip(_ urls: [URL], to directory: URL, password: String? = nil, progress: ((_ progress: Double) -> Void)? = nil) {
do {
try Zip.zipFiles(paths: urls, zipFilePath: directory, password: password) { (p) in
progress?(p)
}
} catch let error {
progress?(1)
#if DEBUG
print("MRFile zip failed: \(error)\n")
#endif
}
}
public class func unzip(_ url: URL,
to directory: URL,
password: String? = nil,
progress: ((_ progress: Double) -> Void)? = nil,
completion: ((_ fileURL: URL?, _ error: Error?) -> Void)? = nil) {
do {
try Zip.unzipFile(url, destination: directory, overwrite: true, password: password, progress: progress, fileOutputHandler: { url in
completion?(url, nil)
})
} catch let err {
progress?(1)
completion?(nil, error(MRFilesErrorCode.unzipError, msg: "文件解压失败"))
#if DEBUG
print("MRFile unzip failed: \(err)\n")
#endif
}
}
}
// MARK: - 语法糖 // MARK: - 语法糖
extension String { extension String {
public func isPathExists() -> Bool { public func isPathExists() -> Bool {
...@@ -439,6 +479,26 @@ extension URL { ...@@ -439,6 +479,26 @@ extension URL {
} }
} }
extension URL {
public func zip(to directory: URL, password: String? = nil, progress: ((_ progress: Double) -> Void)? = nil) {
MRFiles.zip([self], to: directory, password: password, progress: progress)
}
public func unzip(to directory: URL? = nil,
password: String? = nil,
progress: ((_ progress: Double) -> Void)? = nil,
completion: ((_ fileURL: URL?, _ error: Error?) -> Void)? = nil) {
let destination = directory ?? self.deletingLastPathComponent()
MRFiles.unzip(self, to: destination, password: password, progress: progress, completion: completion)
}
}
extension Array where Element == URL {
public func zip(to directory: URL, password: String? = nil, progress: ((_ progress: Double) -> Void)? = nil) {
MRFiles.zip(self, to: directory, password: password, progress: progress)
}
}
extension Data { extension Data {
@discardableResult @discardableResult
public func syncWrite(to url: URL, force: Bool = true) -> Error? { public func syncWrite(to url: URL, force: Bool = true) -> Error? {
......
...@@ -6,6 +6,7 @@ target 'MRFramework' do ...@@ -6,6 +6,7 @@ target 'MRFramework' do
use_frameworks! use_frameworks!
pod 'SnapKit', '4.2.0', :inhibit_warnings => true pod 'SnapKit', '4.2.0', :inhibit_warnings => true
pod 'KeychainAccess', '3.2.0' pod 'KeychainAccess', '3.2.0'
pod 'Zip'
# Pods for MRFramework # Pods for MRFramework
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment