Repository: expo/expo
File: packages/expo-video/ios/Cache/CachedResource.swift (Swift)

Code before:
      expectedContentLength: response.expectedContentLength,
      mimeType: response.mimeType,
      supportsByteRangeAccess: urlResponseSupportsByteRangeAcces(response),
      headerFields: headers,
      savePath: dataPath + VideoCacheManager.mediaInfoSuffix
    )
    mediaInfo?.saveToFile()
  }

  func fill(forLoadingRequest request: AVAssetResourceLoadingRequest) {
    guard let mediaInfo, let mimeType = mediaInfo.mimeType else {
      return
    }
    let fakeResponse = HTTPURLResponse(url: url, statusCode: 200, httpVersion: nil, headerFields: mediaInfo.headerFields)
    let contentType = UTType(mimeType: mimeType)?.identifier
    if let contentType {
      request.contentInformationRequest?.contentType = contentType
      request.contentInformationRequest?.contentLength = mediaInfo.expectedContentLength
      request.contentInformationRequest?.isByteRangeAccessSupported = mediaInfo.supportsByteRangeAccess
      request.response = fakeResponse
    }
  }

  func writeData(data: Data, offset: Int64) async {
    guard !data.isEmpty else {
      log.warn("Attempted to write empty data at offset \(offset), skipping")
      return
    }

    guard offset >= 0 else {
      log.error("Invalid negative offset: \(offset)")
      return
    }

    do {
      try await writeCoordinator.performWrite(
        data: data,
        offset: offset,
        fileHandle: fileHandle,
        mediaInfo: mediaInfo
      )
    } catch {
      log.warn("Failed to write at offset \(offset) with the file handle: \(error)")
    }
  }

  // Returns data for the requested range if fully cached
  // Expects 'from' and 'to' as inclusive byte positions
  func requestData(from: Int64, to: Int64) -> Data? {
    guard from <= to else {
      log.error("Invalid range: from=\(from) > to=\(to)")

Review comment (suggestion):
Might be a good idea to prefix logs with the package name
```suggestion
      log.warn("[expo-video] Attempted to write empty data at offset \(offset), skipping")
```

Code after:
      expectedContentLength: response.expectedContentLength,
      mimeType: response.mimeType,
      supportsByteRangeAccess: urlResponseSupportsByteRangeAcces(response),
      headerFields: headers,
      savePath: dataPath + VideoCacheManager.mediaInfoSuffix
    )
    mediaInfo?.saveToFile()
  }

  func fill(forLoadingRequest request: AVAssetResourceLoadingRequest) {
    guard let mediaInfo, let mimeType = mediaInfo.mimeType else {
      return
    }
    let fakeResponse = HTTPURLResponse(url: url, statusCode: 200, httpVersion: nil, headerFields: mediaInfo.headerFields)
    let contentType = UTType(mimeType: mimeType)?.identifier
    if let contentType {
      request.contentInformationRequest?.contentType = contentType
      request.contentInformationRequest?.contentLength = mediaInfo.expectedContentLength
      request.contentInformationRequest?.isByteRangeAccessSupported = mediaInfo.supportsByteRangeAccess
      request.response = fakeResponse
    }
  }

  func writeData(data: Data, offset: Int64) async {
    guard !data.isEmpty else {
      log.warn("[expo-video] Attempted to write empty data at offset \(offset), skipping")
      return
    }

    guard offset >= 0 else {
      log.error("Invalid negative offset: \(offset)")
      return
    }

    do {
      try await writeCoordinator.performWrite(
        data: data,
        offset: offset,
        fileHandle: fileHandle,
        mediaInfo: mediaInfo
      )
    } catch {
      log.warn("[expo-video] Failed to write at offset \(offset) with the file handle: \(error)")
    }
  }

  // Returns data for the requested range if fully cached
  // Expects 'from' and 'to' as inclusive byte positions
  func requestData(from: Int64, to: Int64) -> Data? {
    guard from <= to else {
      log.error("Invalid range: from=\(from) > to=\(to)")