Skip to content

Commit

Permalink
Merge pull request hyperoslo#206 from hyperoslo/feature/file-extensions
Browse files Browse the repository at this point in the history
Feature: file extensions
  • Loading branch information
vadymmarkov committed Aug 13, 2018
2 parents d040c26 + 80ac19d commit 80d45eb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Source/Shared/Storage/DiskStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,15 @@ extension DiskStorage {
- Returns: A md5 string
*/
func makeFileName(for key: String) -> String {
return MD5(key)
let fileExtension = URL(fileURLWithPath: key).pathExtension
let fileName = MD5(key)

switch fileExtension.isEmpty {
case true:
return fileName
case false:
return "\(fileName).\(fileExtension)"
}
}

/**
Expand Down
10 changes: 10 additions & 0 deletions Tests/iOS/Tests/Storage/DiskStorageTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ final class DiskStorageTests: XCTestCase {
XCTAssertEqual(entry?.expiry.date, expiry.date)
}

func testCacheEntryPath() throws {
let key = "test.mp4"
try storage.setObject(testObject, forKey: key)
let entry = try storage.entry(forKey: key)
let filePath = storage.makeFilePath(for: key)

XCTAssertEqual(entry.filePath, filePath)
}

/// Test that it resolves cached object
func testSetObject() throws {
try storage.setObject(testObject, forKey: key)
Expand Down Expand Up @@ -198,6 +207,7 @@ final class DiskStorageTests: XCTestCase {
/// Test that it returns a correct file name
func testMakeFileName() {
XCTAssertEqual(storage.makeFileName(for: key), MD5(key))
XCTAssertEqual(storage.makeFileName(for: "test.mp4"), "\(MD5("test.mp4")).mp4")
}

/// Test that it returns a correct file path
Expand Down

0 comments on commit 80d45eb

Please sign in to comment.