mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-16 19:30:29 +00:00
Attempt to fix data load conditions
This commit is contained in:
parent
5327342b92
commit
7e1bf68b71
@ -104,7 +104,8 @@ private func readPacketCallback(userData: UnsafeMutableRawPointer?, buffer: Unsa
|
||||
var completedRequest = false
|
||||
let disposable = data.start(next: { result in
|
||||
let (data, isComplete) = result
|
||||
if data.count == readCount || isComplete{
|
||||
if data.count == readCount || isComplete {
|
||||
precondition(data.count <= readCount)
|
||||
fetchedData = data
|
||||
completedRequest = true
|
||||
semaphore.signal()
|
||||
@ -178,6 +179,7 @@ private func readPacketCallback(userData: UnsafeMutableRawPointer?, buffer: Unsa
|
||||
}
|
||||
}
|
||||
if let fetchedData = fetchedData {
|
||||
precondition(fetchedData.count <= readCount)
|
||||
fetchedData.withUnsafeBytes { bytes -> Void in
|
||||
precondition(bytes.baseAddress != nil)
|
||||
memcpy(buffer, bytes.baseAddress, fetchedData.count)
|
||||
|
||||
@ -884,7 +884,25 @@ final class MediaBoxFileContext {
|
||||
func data(range: Range<Int32>, waitUntilAfterInitialFetch: Bool, next: @escaping (MediaResourceData) -> Void) -> Disposable {
|
||||
switch self.content {
|
||||
case let .complete(path, size):
|
||||
next(MediaResourceData(path: path, offset: min(size, Int(range.lowerBound)), size: max(0, min(Int(range.upperBound), size) - Int(range.lowerBound)), complete: true))
|
||||
var lowerBound = range.lowerBound
|
||||
if lowerBound < 0 {
|
||||
lowerBound = 0
|
||||
}
|
||||
if lowerBound > Int(size) {
|
||||
lowerBound = Int32(clamping: size)
|
||||
}
|
||||
var upperBound = range.upperBound
|
||||
if upperBound < 0 {
|
||||
upperBound = 0
|
||||
}
|
||||
if upperBound > Int(size) {
|
||||
upperBound = Int32(clamping: size)
|
||||
}
|
||||
if upperBound < lowerBound {
|
||||
upperBound = lowerBound
|
||||
}
|
||||
|
||||
next(MediaResourceData(path: path, offset: Int(lowerBound), size: Int(upperBound - lowerBound), complete: true))
|
||||
return EmptyDisposable
|
||||
case let .partial(file):
|
||||
return file.data(range: range, waitUntilAfterInitialFetch: waitUntilAfterInitialFetch, next: next)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user