Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: file extensions #206

Merged
merged 2 commits into from Aug 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion Source/Shared/Storage/DiskStorage.swift
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
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