Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions Sources/OLEKit/OLEFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,35 +33,30 @@ public final class OLEFile {
guard FileManager.default.fileExists(atPath: path)
else { throw OLEError.fileDoesNotExist(path) }

let attributes = try FileManager.default.attributesOfItem(atPath: path)
// swiftlint:disable:next force_cast
let fileSize = attributes[FileAttributeKey.size] as! Int

guard let fileHandle = FileHandle(forReadingAtPath: path)
else { throw OLEError.fileNotAvailableForReading(path: path) }

let allData = fileHandle.readDataToEndOfFile()
fileHandle.seek(toFileOffset: UInt64(0))

try self.init(data: allData, fileSize: fileSize, path: path)
try self.init(data: allData, path: path)
}

#if os(iOS) || os(watchOS) || os(tvOS) || os(macOS)

public convenience init(_ fileWrapper: FileWrapper) throws {
let fileName = fileWrapper.filename ?? ""

guard
let data = fileWrapper.regularFileContents,
let fileSize = fileWrapper.fileAttributes[FileAttributeKey.size.rawValue] as? Int
guard let data = fileWrapper.regularFileContents
else { throw OLEError.fileDoesNotExist(fileName) }

try self.init(data: data, fileSize: fileSize, path: fileName)
try self.init(data: data, path: fileName)
}

#endif

private init(data: Data, fileSize: Int, path: String) throws {
private init(data: Data, path: String) throws {
let fileSize = data.count
guard fileSize >= 512
else { throw OLEError.incompleteHeader }

Expand Down