Files
praca_inzynierska/Implementation/PeeredTests/Helpers/InMemoryStorageProvider.swift
T
2026-05-24 20:40:25 +02:00

28 lines
796 B
Swift

import Foundation
@testable import Peered
final class InMemoryStorageProvider: StorageProvider {
private(set) var files: [String: Data] = [:]
func contentsOfDirectory(atPath path: String) throws -> [String] {
return files.keys.compactMap { filePath -> String? in
guard filePath.hasPrefix(path) else { return nil }
let remainder = String(filePath.dropFirst(path.count))
let stripped = remainder.hasPrefix("/") ? String(remainder.dropFirst()) : remainder
guard !stripped.isEmpty, !stripped.contains("/") else { return nil }
return stripped
}
}
@discardableResult
func createFile(
atPath path: String,
contents data: Data?,
attributes attr: [FileAttributeKey: Any]?
) -> Bool {
files[path] = data ?? Data()
return true
}
}