File tree Expand file tree Collapse file tree 3 files changed +25
-6
lines changed Expand file tree Collapse file tree 3 files changed +25
-6
lines changed Original file line number Diff line number Diff line change 1+ //
2+ // FileManager+FileOperations.swift
3+ //
4+
5+ import Foundation
6+
7+ extension FileManager {
8+
9+ // Work around Swift compiler not bridging Dictionary
10+ // and NSDictionary properly when calling attributesOfItem
11+ func fileSizeOfItem(
12+ atPath path: String
13+ ) throws -> UInt64 {
14+ ( try attributesOfItem ( atPath: path) as NSDictionary )
15+ . fileSize ( )
16+ }
17+ }
Original file line number Diff line number Diff line change @@ -56,7 +56,7 @@ class ChunkedFile {
5656 func openFile( fileURL: URL ) throws {
5757 if state == nil {
5858 do {
59- let fileSize = try ( fileManager. attributesOfItem ( atPath: fileURL. path) as NSDictionary ) . fileSize ( )
59+ let fileSize = try fileManager. fileSizeOfItem ( atPath: fileURL. path)
6060 let fileHandle = try FileHandle ( forReadingFrom: fileURL)
6161 state = State (
6262 fileHandle: fileHandle,
@@ -93,9 +93,9 @@ class ChunkedFile {
9393 }
9494 let data = try fileHandle. read ( upToCount: chunkSize)
9595
96- let fileSize = try ( fileManager. attributesOfItem (
96+ let fileSize = try fileManager. fileSizeOfItem (
9797 atPath: fileURL. path
98- ) as NSDictionary ) . fileSize ( )
98+ )
9999
100100 guard let data = data else {
101101 // Called while already at the end of the file. We read zero bytes, "ending" at the end of the file
Original file line number Diff line number Diff line change @@ -88,7 +88,9 @@ class ChunkedFileUploader {
8888 let task = Task . detached { [ self ] in
8989 do {
9090 // It's fine if it's already open, that's handled by ignoring the call
91- let fileSize = ( try FileManager . default. attributesOfItem ( atPath: uploadInfo. videoFile. path) as NSDictionary ) . fileSize ( )
91+ let fileSize = try FileManager . default. fileSizeOfItem (
92+ atPath: uploadInfo. videoFile. path
93+ )
9294 let result = try await makeWorker ( ) . performUpload ( )
9395 file. close ( )
9496
@@ -240,9 +242,9 @@ fileprivate actor Worker {
240242 try chunkedFile. seekTo ( byte: startingReadCount)
241243
242244 let startTime = Date ( ) . timeIntervalSince1970
243- let fileSize = ( try FileManager . default. attributesOfItem (
245+ let fileSize = try FileManager . default. fileSizeOfItem (
244246 atPath: uploadInfo. videoFile. path
245- ) as NSDictionary ) . fileSize ( )
247+ )
246248
247249 let wideFileSize : Int64
248250
You can’t perform that action at this time.
0 commit comments