Skip to content

Commit b633fa1

Browse files
committed
Fixed a crash that made large uploads consume way too much memory
1 parent 2b965d9 commit b633fa1

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

Sources/TUSKit/Tasks/UploadDataTask.swift

+7-5
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,12 @@ final class UploadDataTask: NSObject, IdentifiableTask {
7676
return
7777
}
7878

79-
let dataToUpload: Data
79+
let dataSize: Int
8080
let file: URL
8181
do {
82-
dataToUpload = try loadData()
82+
let attr = try FileManager.default.attributesOfItem(atPath: metaData.filePath.path)
83+
dataSize = attr[FileAttributeKey.size] as! Int
84+
8385
file = try prepareUploadFile()
8486
} catch let error {
8587
let tusError = TUSClientError.couldNotLoadData(underlyingError: error)
@@ -104,7 +106,7 @@ final class UploadDataTask: NSObject, IdentifiableTask {
104106
sessionTask = task
105107

106108
if #available(iOS 11.0, macOS 10.13, *) {
107-
observeTask(task: task, size: dataToUpload.count)
109+
observeTask(task: task, size: dataSize)
108110
}
109111
}
110112

@@ -190,8 +192,8 @@ final class UploadDataTask: NSObject, IdentifiableTask {
190192
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.
191193
return try fileHandle.readToEnd()
192194
*/
193-
} else { // No range, older versions
194-
data = fileHandle.readDataToEndOfFile()
195+
} else { // No range, we're uploading the file in full so no need to read / recopy
196+
return metaData.filePath
195197
}
196198

197199
return try files.store(data: data, id: metaData.id, preferredFileExtension: "uploadData")

TUSKitExample/TUSKitExample.xcodeproj/project.pbxproj

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
archiveVersion = 1;
44
classes = {
55
};
6-
objectVersion = 52;
6+
objectVersion = 54;
77
objects = {
88

99
/* Begin PBXBuildFile section */
@@ -545,7 +545,7 @@
545545
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
546546
CODE_SIGN_STYLE = Automatic;
547547
DEVELOPMENT_ASSET_PATHS = "\"TUSKitExample/Preview Content\"";
548-
DEVELOPMENT_TEAM = G43DLT797F;
548+
DEVELOPMENT_TEAM = 4JMM8JMG3H;
549549
ENABLE_PREVIEWS = YES;
550550
INFOPLIST_FILE = TUSKitExample/Info.plist;
551551
IPHONEOS_DEPLOYMENT_TARGET = 14.1;
@@ -567,7 +567,7 @@
567567
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
568568
CODE_SIGN_STYLE = Automatic;
569569
DEVELOPMENT_ASSET_PATHS = "\"TUSKitExample/Preview Content\"";
570-
DEVELOPMENT_TEAM = G43DLT797F;
570+
DEVELOPMENT_TEAM = 4JMM8JMG3H;
571571
ENABLE_PREVIEWS = YES;
572572
INFOPLIST_FILE = TUSKitExample/Info.plist;
573573
IPHONEOS_DEPLOYMENT_TARGET = 14.1;

0 commit comments

Comments
 (0)