Commit d0006699 authored by József Vesza's avatar József Vesza

Added support for CBZ files.

parent 5b0f8066
...@@ -79,6 +79,8 @@ ...@@ -79,6 +79,8 @@
347E3AD81C1E04C900A11FD3 /* Zip.swift in Sources */ = {isa = PBXBuildFile; fileRef = 347E3AD71C1E04C900A11FD3 /* Zip.swift */; }; 347E3AD81C1E04C900A11FD3 /* Zip.swift in Sources */ = {isa = PBXBuildFile; fileRef = 347E3AD71C1E04C900A11FD3 /* Zip.swift */; };
34940A241C58876200D41574 /* 3crBXeO.gif in Resources */ = {isa = PBXBuildFile; fileRef = 34940A221C58876200D41574 /* 3crBXeO.gif */; }; 34940A241C58876200D41574 /* 3crBXeO.gif in Resources */ = {isa = PBXBuildFile; fileRef = 34940A221C58876200D41574 /* 3crBXeO.gif */; };
34940A251C58876200D41574 /* kYkLkPf.gif in Resources */ = {isa = PBXBuildFile; fileRef = 34940A231C58876200D41574 /* kYkLkPf.gif */; }; 34940A251C58876200D41574 /* kYkLkPf.gif in Resources */ = {isa = PBXBuildFile; fileRef = 34940A231C58876200D41574 /* kYkLkPf.gif */; };
BBF824D51CA60383008FF3C5 /* bb8.cbz in Resources */ = {isa = PBXBuildFile; fileRef = BBF824D31CA60383008FF3C5 /* bb8.cbz */; };
BBF824D61CA60383008FF3C5 /* bb8.xyz in Resources */ = {isa = PBXBuildFile; fileRef = BBF824D41CA60383008FF3C5 /* bb8.xyz */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */ /* Begin PBXContainerItemProxy section */
...@@ -143,6 +145,8 @@ ...@@ -143,6 +145,8 @@
347E3AD71C1E04C900A11FD3 /* Zip.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Zip.swift; sourceTree = "<group>"; }; 347E3AD71C1E04C900A11FD3 /* Zip.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Zip.swift; sourceTree = "<group>"; };
34940A221C58876200D41574 /* 3crBXeO.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; name = 3crBXeO.gif; path = Images/3crBXeO.gif; sourceTree = "<group>"; }; 34940A221C58876200D41574 /* 3crBXeO.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; name = 3crBXeO.gif; path = Images/3crBXeO.gif; sourceTree = "<group>"; };
34940A231C58876200D41574 /* kYkLkPf.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; name = kYkLkPf.gif; path = Images/kYkLkPf.gif; sourceTree = "<group>"; }; 34940A231C58876200D41574 /* kYkLkPf.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; name = kYkLkPf.gif; path = Images/kYkLkPf.gif; sourceTree = "<group>"; };
BBF824D31CA60383008FF3C5 /* bb8.cbz */ = {isa = PBXFileReference; lastKnownFileType = file; path = bb8.cbz; sourceTree = "<group>"; };
BBF824D41CA60383008FF3C5 /* bb8.xyz */ = {isa = PBXFileReference; lastKnownFileType = file; path = bb8.xyz; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */ /* Begin PBXFrameworksBuildPhase section */
...@@ -262,6 +266,8 @@ ...@@ -262,6 +266,8 @@
347E3A821C1DFFB500A11FD3 /* ZipTests */ = { 347E3A821C1DFFB500A11FD3 /* ZipTests */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
BBF824D31CA60383008FF3C5 /* bb8.cbz */,
BBF824D41CA60383008FF3C5 /* bb8.xyz */,
34940A221C58876200D41574 /* 3crBXeO.gif */, 34940A221C58876200D41574 /* 3crBXeO.gif */,
34940A231C58876200D41574 /* kYkLkPf.gif */, 34940A231C58876200D41574 /* kYkLkPf.gif */,
3443A3FC1C4AD199004AD173 /* bb8.zip */, 3443A3FC1C4AD199004AD173 /* bb8.zip */,
...@@ -467,9 +473,11 @@ ...@@ -467,9 +473,11 @@
isa = PBXResourcesBuildPhase; isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
BBF824D51CA60383008FF3C5 /* bb8.cbz in Resources */,
34940A251C58876200D41574 /* kYkLkPf.gif in Resources */, 34940A251C58876200D41574 /* kYkLkPf.gif in Resources */,
3443A3FD1C4AD199004AD173 /* bb8.zip in Resources */, 3443A3FD1C4AD199004AD173 /* bb8.zip in Resources */,
34940A241C58876200D41574 /* 3crBXeO.gif in Resources */, 34940A241C58876200D41574 /* 3crBXeO.gif in Resources */,
BBF824D61CA60383008FF3C5 /* bb8.xyz in Resources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
......
...@@ -64,7 +64,7 @@ public class Zip { ...@@ -64,7 +64,7 @@ public class Zip {
guard let path = zipFilePath.path where destination.path != nil else { guard let path = zipFilePath.path where destination.path != nil else {
throw ZipError.FileNotFound throw ZipError.FileNotFound
} }
if fileManager.fileExistsAtPath(path) == false || zipFilePath.pathExtension != "zip" { if fileManager.fileExistsAtPath(path) == false || fileExtensionIsInvalid(zipFilePath.pathExtension) {
throw ZipError.FileNotFound throw ZipError.FileNotFound
} }
...@@ -281,6 +281,17 @@ public class Zip { ...@@ -281,6 +281,17 @@ public class Zip {
} }
} }
/**
Check if file extension is invalid.
- parameter fileExtension: A file extension.
- returns: false if the extension is "zip" or "cbz", otherwise true.
*/
internal class func fileExtensionIsInvalid(fileExtension: String?) -> Bool {
guard let fileExtension = fileExtension else { return true }
return ["zip", "cbz"].contains(fileExtension)
}
} }
\ No newline at end of file
...@@ -165,5 +165,15 @@ class ZipTests: XCTestCase { ...@@ -165,5 +165,15 @@ class ZipTests: XCTestCase {
} }
} }
func testFileExtensionIsInvalidForValidUrl() {
let fileUrl = NSBundle(forClass: ZipTests.self).URLForResource("bb8", withExtension: "cbz")
let result = Zip.fileExtensionIsInvalid(fileUrl?.pathExtension)
XCTAssertTrue(result)
}
func testFileExtensionIsInvalidForInvalidUrl() {
let fileUrl = NSBundle(forClass: ZipTests.self).URLForResource("bb8", withExtension: "xyz")
let result = Zip.fileExtensionIsInvalid(fileUrl?.pathExtension)
XCTAssertFalse(result)
}
} }
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 to comment