From 809aa4ff96f25aa302c06c1ea676dced95fae459 Mon Sep 17 00:00:00 2001 From: John Rommel Estropia Date: Sat, 1 Jul 2017 11:50:23 +0900 Subject: [PATCH] allow querying file size on SQLiteStore --- .../CoreStore+CustomDebugStringConvertible.swift | 3 ++- Sources/SQLiteStore.swift | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Sources/CoreStore+CustomDebugStringConvertible.swift b/Sources/CoreStore+CustomDebugStringConvertible.swift index dc197e3..a1f5e80 100644 --- a/Sources/CoreStore+CustomDebugStringConvertible.swift +++ b/Sources/CoreStore+CustomDebugStringConvertible.swift @@ -868,7 +868,8 @@ extension SQLiteStore: CustomDebugStringConvertible, CoreStoreDebugStringConvert ("storeOptions", self.storeOptions as Any), ("fileURL", self.fileURL), ("migrationMappingProviders", self.migrationMappingProviders), - ("localStorageOptions", self.localStorageOptions) + ("localStorageOptions", self.localStorageOptions), + ("fileSize", self.fileSize() as Any) ) } } diff --git a/Sources/SQLiteStore.swift b/Sources/SQLiteStore.swift index fff62ff..42c6505 100644 --- a/Sources/SQLiteStore.swift +++ b/Sources/SQLiteStore.swift @@ -117,6 +117,20 @@ public final class SQLiteStore: LocalStorage { ) } + /** + Queries the file size (in bytes) of the store, or `nil` if the file does not exist yet + */ + public func fileSize() -> UInt64? { + + guard let attribute = try? FileManager.default.attributesOfItem(atPath: self.fileURL.path), + let sizeAttribute = attribute[.size], + let fileSize = sizeAttribute as? NSNumber else { + + return nil + } + return fileSize.uint64Value + } + // MARK: StorageInterface