Skip to content

Commit

Permalink
Fixed a crash that made large uploads consume way too much memory
Browse files Browse the repository at this point in the history
  • Loading branch information
donnywals committed Sep 2, 2024
1 parent 2b965d9 commit b633fa1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
12 changes: 7 additions & 5 deletions Sources/TUSKit/Tasks/UploadDataTask.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,12 @@ final class UploadDataTask: NSObject, IdentifiableTask {
return
}

let dataToUpload: Data
let dataSize: Int
let file: URL
do {
dataToUpload = try loadData()
let attr = try FileManager.default.attributesOfItem(atPath: metaData.filePath.path)
dataSize = attr[FileAttributeKey.size] as! Int

file = try prepareUploadFile()
} catch let error {
let tusError = TUSClientError.couldNotLoadData(underlyingError: error)
Expand All @@ -104,7 +106,7 @@ final class UploadDataTask: NSObject, IdentifiableTask {
sessionTask = task

if #available(iOS 11.0, macOS 10.13, *) {
observeTask(task: task, size: dataToUpload.count)
observeTask(task: task, size: dataSize)
}
}

Expand Down Expand Up @@ -190,8 +192,8 @@ final class UploadDataTask: NSObject, IdentifiableTask {
Note that compiler and api says that readToEnd is available on macOS 10.15.4 and higher, but yet github actions of 10.15.7 fails to find the member.
return try fileHandle.readToEnd()
*/
} else { // No range, older versions
data = fileHandle.readDataToEndOfFile()
} else { // No range, we're uploading the file in full so no need to read / recopy
return metaData.filePath
}

return try files.store(data: data, id: metaData.id, preferredFileExtension: "uploadData")
Expand Down
6 changes: 3 additions & 3 deletions TUSKitExample/TUSKitExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 52;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -545,7 +545,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_ASSET_PATHS = "\"TUSKitExample/Preview Content\"";
DEVELOPMENT_TEAM = G43DLT797F;
DEVELOPMENT_TEAM = 4JMM8JMG3H;
ENABLE_PREVIEWS = YES;
INFOPLIST_FILE = TUSKitExample/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 14.1;
Expand All @@ -567,7 +567,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_ASSET_PATHS = "\"TUSKitExample/Preview Content\"";
DEVELOPMENT_TEAM = G43DLT797F;
DEVELOPMENT_TEAM = 4JMM8JMG3H;
ENABLE_PREVIEWS = YES;
INFOPLIST_FILE = TUSKitExample/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 14.1;
Expand Down

0 comments on commit b633fa1

Please sign in to comment.