@@ -224,13 +224,15 @@ public class Cryptor {
224
224
// encrypt and write ciphertext content:
225
225
var chunkNumber : UInt64 = 0
226
226
while cleartextStream. hasBytesAvailable {
227
- guard let cleartextChunk = try cleartextStream. read ( maxLength: cleartextChunkSize) else {
228
- continue
227
+ try autoreleasepool {
228
+ guard let cleartextChunk = try cleartextStream. read ( maxLength: cleartextChunkSize) else {
229
+ return
230
+ }
231
+ let ciphertextChunk = try encryptSingleChunk ( cleartextChunk, chunkNumber: chunkNumber, headerNonce: header. nonce, fileKey: header. contentKey)
232
+ ciphertextStream. write ( ciphertextChunk, maxLength: ciphertextChunk. count)
233
+ progress. completedUnitCount += Int64 ( ciphertextChunk. count)
234
+ chunkNumber += 1
229
235
}
230
- let ciphertextChunk = try encryptSingleChunk ( cleartextChunk, chunkNumber: chunkNumber, headerNonce: header. nonce, fileKey: header. contentKey)
231
- ciphertextStream. write ( ciphertextChunk, maxLength: ciphertextChunk. count)
232
- progress. completedUnitCount += Int64 ( ciphertextChunk. count)
233
- chunkNumber += 1
234
236
}
235
237
}
236
238
@@ -286,13 +288,15 @@ public class Cryptor {
286
288
let ciphertextChunkSize = contentCryptor. nonceLen + cleartextChunkSize + contentCryptor. tagLen
287
289
var chunkNumber : UInt64 = 0
288
290
while ciphertextStream. hasBytesAvailable {
289
- guard let ciphertextChunk = try ciphertextStream. read ( maxLength: ciphertextChunkSize) else {
290
- continue
291
+ try autoreleasepool {
292
+ guard let ciphertextChunk = try ciphertextStream. read ( maxLength: ciphertextChunkSize) else {
293
+ return
294
+ }
295
+ let cleartextChunk = try decryptSingleChunk ( ciphertextChunk, chunkNumber: chunkNumber, headerNonce: header. nonce, fileKey: header. contentKey)
296
+ cleartextStream. write ( cleartextChunk, maxLength: cleartextChunk. count)
297
+ progress. completedUnitCount += Int64 ( cleartextChunk. count)
298
+ chunkNumber += 1
291
299
}
292
- let cleartextChunk = try decryptSingleChunk ( ciphertextChunk, chunkNumber: chunkNumber, headerNonce: header. nonce, fileKey: header. contentKey)
293
- cleartextStream. write ( cleartextChunk, maxLength: cleartextChunk. count)
294
- progress. completedUnitCount += Int64 ( cleartextChunk. count)
295
- chunkNumber += 1
296
300
}
297
301
}
298
302
0 commit comments