Skip to content

Commit accbb5c

Browse files
author
Alexey Novikov
committed
Improve epub detection
1 parent 26fc71a commit accbb5c

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

Sources/FileType/zip+office.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func matchZipHeader(_ data: Data, _ match: (ZipHeader) -> Bool) -> Bool {
2323
position += 30 + filenameLength + extraFieldLength
2424

2525
if zipHeader.filename == "mimetype", compressedSize == uncompressedSize {
26-
zipHeader.mimeType = data.getString(from: position ..< position + compressedSize)
26+
zipHeader.mimeType = data.getString(from: position ..< position + compressedSize)?.trimmingCharacters(in: .whitespacesAndNewlines)
2727
}
2828

2929
if match(zipHeader) {

Tests/FileTypeTests/FileTypeTests.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ final class FileTypeTests: XCTestCase {
175175
testFileType("fixture.ppt.cfb", type: .cfb)
176176
testFileType("fixture-2.doc.cfb", type: .cfb)
177177
}
178-
178+
179179
func testMatroska() {
180180
testFileType("fixture2.mkv", type: .mkv)
181181
testFileType("fixture-null.webm", type: .webm)
@@ -189,6 +189,10 @@ final class FileTypeTests: XCTestCase {
189189
testFileType("fixture-printed.pdf", type: .pdf)
190190
}
191191

192+
func testEPUB() {
193+
testFileType("fixture-crlf.epub", type: .epub)
194+
}
195+
192196
func testBytesCountForType() {
193197
XCTAssertEqual(FileType.getBytesCountFor(type: .ac3), 2)
194198
XCTAssertEqual(FileType.getBytesCountFor(type: .zip), 4)
@@ -223,7 +227,9 @@ final class FileTypeTests: XCTestCase {
223227
("testASF", testASF),
224228
("testJXL", testJXL),
225229
("testCFB", testCFB),
230+
("testMatroska", testMatroska),
226231
("testPDF", testPDF),
232+
("testEPUB", testEPUB),
227233

228234
("testBytesCountForType", testBytesCountForType),
229235
("testBytesCountForTypes", testBytesCountForTypes),

Tests/Fixtures/fixture-crlf.epub

718 KB
Binary file not shown.

0 commit comments

Comments
 (0)