Skip to content

Commit 0da3734

Browse files
committed
Read off file size
1 parent 018448d commit 0da3734

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

Sources/MuxUploadSDK/InternalUtilities/ChunkedFile.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,9 @@ class ChunkedFile {
9292
throw ChunkedFileError.invalidState("doReadNextChunk called without file handle. Did you call open()?")
9393
}
9494
let data = try fileHandle.read(upToCount: chunkSize)
95-
9695
let fileSize = try fileManager.fileSizeOfItem(
9796
atPath: fileURL.path
9897
)
99-
10098
guard let data = data else {
10199
// Called while already at the end of the file. We read zero bytes, "ending" at the end of the file
102100
return FileChunk(startByte: fileSize, endByte: fileSize, totalFileSize: fileSize, chunkData: Data(capacity: 0))

Sources/MuxUploadSDK/Upload/ChunkedFileUploader.swift

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class ChunkedFileUploader {
2424
private var delegates: [String : ChunkedFileUploaderDelegate] = [:]
2525

2626
private let file: ChunkedFile
27-
private var currentWorkTask: Task<(), Never>? = nil
27+
private var currentWorkTask: Task<(), Error>? = nil
2828
private var _currentState: InternalUploadState = .ready
2929
private var overallProgress: Progress = Progress()
3030
private var lastReadCount: UInt64 = 0
@@ -94,7 +94,7 @@ class ChunkedFileUploader {
9494
do {
9595
// It's fine if it's already open, that's handled by ignoring the call
9696
let fileSize = try FileManager.default.fileSizeOfItem(
97-
atPath: uploadInfo.videoFile.path
97+
atPath: inputFileURL.path
9898
)
9999
let result = try await makeWorker().performUpload()
100100
file.close()
@@ -137,21 +137,26 @@ class ChunkedFileUploader {
137137
} else {
138138
MuxUploadSDK.logger?.debug("Task finished due to error in state \(String(describing: self.currentState))")
139139
let uploadError = InternalUploaderError(reason: error, lastByte: lastReadCount)
140+
notifyStateFromWorker(.failure(uploadError))
140141

141142
if shouldReport {
143+
let fileSize = try FileManager.default.fileSizeOfItem(
144+
atPath: inputFileURL.path
145+
)
146+
142147
#warning("Start and end time need to be fixed")
143148
reporter.reportUploadFailure(
144149
transportStartTime: 0,
145150
transportEndTime: 0,
146151
errorDescription: uploadError.localizedDescription,
147-
inputSize: file.fileSize,
152+
inputSize: fileSize,
148153
inputStandardizationEnabled: uploadInfo.options.inputStandardization.isEnabled,
149154
inputDuration: 0.0,
150155
uploadURL: uploadInfo.uploadURL
151156
)
152157
}
153158

154-
notifyStateFromWorker(.failure(uploadError))
159+
155160
}
156161
}
157162
}
@@ -289,9 +294,8 @@ fileprivate actor Worker {
289294

290295
let startTime = Date().timeIntervalSince1970
291296
let fileSize = try FileManager.default.fileSizeOfItem(
292-
atPath: uploadInfo.videoFile.path
297+
atPath: inputFileURL.path
293298
)
294-
295299
let wideFileSize: Int64
296300

297301
// Prevent overflow if UInt64 exceeds Int64.max

0 commit comments

Comments
 (0)