@@ -53,7 +53,6 @@ class Downloader: NSObject, ObservableObject {
53
53
if let attributes = try ? FileManager . default. attributesOfItem ( atPath: incompletePath. path) ,
54
54
let fileSize = attributes [ . size] as? Int
55
55
{
56
- print ( " [Downloader] Found existing incomplete file for \( destination. lastPathComponent) : \( fileSize) bytes " )
57
56
return fileSize
58
57
}
59
58
}
@@ -122,19 +121,13 @@ class Downloader: NSObject, ObservableObject {
122
121
timeout: TimeInterval ,
123
122
numRetries: Int
124
123
) {
125
- print ( " [Downloader] Setting up download for \( url. lastPathComponent) " )
126
- print ( " [Downloader] Destination: \( destination. path) " )
127
- print ( " [Downloader] Incomplete file: \( tempFilePath? . path ?? " none " ) " )
128
-
129
124
urlSession? . getAllTasks { tasks in
130
125
// If there's an existing pending background task with the same URL, let it proceed.
131
126
if let existing = tasks. filter ( { $0. originalRequest? . url == url } ) . first {
132
127
switch existing. state {
133
128
case . running:
134
- print ( " [Downloader] Task already running for \( url. lastPathComponent) " )
135
129
return
136
130
case . suspended:
137
- print ( " [Downloader] Resuming suspended download task for \( url. lastPathComponent) " )
138
131
existing. resume ( )
139
132
return
140
133
case . canceling, . completed:
@@ -156,15 +149,13 @@ class Downloader: NSObject, ObservableObject {
156
149
if fileManager. fileExists ( atPath: incompleteFilePath. path) {
157
150
let attributes = try fileManager. attributesOfItem ( atPath: incompleteFilePath. path)
158
151
existingSize = attributes [ . size] as? Int ?? 0
159
- print ( " [Downloader] Found incomplete file with \( existingSize) bytes " )
160
152
self . downloadedSize = existingSize
161
153
} else {
162
154
// Create parent directory if needed
163
155
try fileManager. createDirectory ( at: incompleteFilePath. deletingLastPathComponent ( ) , withIntermediateDirectories: true )
164
156
165
157
// Create empty incomplete file
166
158
fileManager. createFile ( atPath: incompleteFilePath. path, contents: nil )
167
- print ( " [Downloader] Created new incomplete file at \( incompleteFilePath. path) " )
168
159
}
169
160
170
161
// Set up the request with appropriate headers
@@ -183,14 +174,11 @@ class Downloader: NSObject, ObservableObject {
183
174
if let expectedSize, expectedSize > 0 {
184
175
let initialProgress = Double ( existingSize) / Double( expectedSize)
185
176
self . downloadState. value = . downloading( initialProgress)
186
- print ( " [Downloader] Resuming from \( existingSize) / \( expectedSize) bytes ( \( Int ( initialProgress * 100 ) ) %) " )
187
177
} else {
188
178
self . downloadState. value = . downloading( 0 )
189
- print ( " [Downloader] Resuming download from byte \( existingSize) " )
190
179
}
191
180
} else {
192
181
self . downloadState. value = . downloading( 0 )
193
- print ( " [Downloader] Starting new download " )
194
182
}
195
183
196
184
request. timeoutInterval = timeout
@@ -209,14 +197,9 @@ class Downloader: NSObject, ObservableObject {
209
197
210
198
// Clean up and move the completed download to its final destination
211
199
tempFile. closeFile ( )
212
- print ( " [Downloader] Download completed with total size \( self . downloadedSize) bytes " )
213
- print ( " [Downloader] Moving incomplete file to destination: \( self . destination. path) " )
214
200
try fileManager. moveDownloadedFile ( from: incompleteFilePath, to: self . destination)
215
-
216
- print ( " [Downloader] Download successfully completed " )
217
201
self . downloadState. value = . completed( self . destination)
218
202
} catch {
219
- print ( " [Downloader] Error: \( error) " )
220
203
self . downloadState. value = . failed( error)
221
204
}
222
205
}
@@ -249,27 +232,15 @@ class Downloader: NSObject, ObservableObject {
249
232
var newRequest = request
250
233
if resumeSize > 0 {
251
234
newRequest. setValue ( " bytes= \( resumeSize) - " , forHTTPHeaderField: " Range " )
252
- print ( " [Downloader] Adding Range header: bytes= \( resumeSize) - " )
253
235
}
254
236
255
237
// Start the download and get the byte stream
256
238
let ( asyncBytes, response) = try await session. bytes ( for: newRequest)
257
239
258
240
guard let httpResponse = response as? HTTPURLResponse else {
259
- print ( " [Downloader] Error: Non-HTTP response received " )
260
241
throw DownloadError . unexpectedError
261
242
}
262
-
263
- print ( " [Downloader] Received HTTP \( httpResponse. statusCode) response " )
264
- if let contentRange = httpResponse. value ( forHTTPHeaderField: " Content-Range " ) {
265
- print ( " [Downloader] Content-Range: \( contentRange) " )
266
- }
267
- if let contentLength = httpResponse. value ( forHTTPHeaderField: " Content-Length " ) {
268
- print ( " [Downloader] Content-Length: \( contentLength) " )
269
- }
270
-
271
243
guard ( 200 ..< 300 ) . contains ( httpResponse. statusCode) else {
272
- print ( " [Downloader] Error: HTTP status code \( httpResponse. statusCode) " )
273
244
throw DownloadError . unexpectedError
274
245
}
275
246
@@ -323,10 +294,7 @@ class Downloader: NSObject, ObservableObject {
323
294
// Verify the downloaded file size matches the expected size
324
295
let actualSize = try tempFile. seekToEnd ( )
325
296
if let expectedSize, expectedSize != actualSize {
326
- print ( " [Downloader] Error: Size mismatch - expected \( expectedSize) bytes but got \( actualSize) bytes " )
327
297
throw DownloadError . unexpectedError
328
- } else {
329
- print ( " [Downloader] Final verification passed, size: \( actualSize) bytes " )
330
298
}
331
299
}
332
300
0 commit comments