What is Chunk count in Modern Concurrency Unit 3?

Hello, iOS champions!
In the struct ByteAccumulator,

  1. What is chunk count? is that a block unit of bytes? why its value is the size of the file divided by 20? why 20?
struct ByteAccumulator: CustomStringConvertible {
  private var offset = 0
  private var counter = -1
  private let name: String
  private let size: Int
  private let chunkCount: Int
  private var bytes: [UInt8]
  var data: Data { return Data(bytes[0..<offset]) }

  /// Creates a named byte accumulator.
  init(name: String, size: Int) {
    self.name = name
    self.size = size
    chunkCount = max(Int(Double(size) / 20), 1)
    bytes = [UInt8](repeating: 0, count: chunkCount)
  }
}

 chunkCount = max(Int(Double(size) / 20), 1) // why 20?
  1. Data of a file is an array of bytes, limited by the size of that file
bytes = [UInt8](repeating: 0, count: size)

but to check whether a batch is completed or not to stop the download, we use chunk count, not the size?

  var isBatchCompleted: Bool {
    return counter >= chunkCount
  }

I hope my questions are clear. Thanks a lot.

This topic was automatically closed after 166 days. New replies are no longer allowed.