Skip to content

Commit

Permalink
Do not use chunks for uncompressed data, use the full range
Browse files Browse the repository at this point in the history
  • Loading branch information
BPerlakiH committed Jun 1, 2024
1 parent 50f5990 commit 530c68a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
6 changes: 2 additions & 4 deletions Model/Utilities/DataStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ struct DataStream<Element>: AsyncSequence {

/// - Parameters:
/// - dataProvider: A place we can read the data from
/// - contentLength: total length of the data
/// - rangeSize: size of the ranges it uses to read the data
init?(dataProvider: any DataProvider<Element>, contentLength: UInt, rangeSize: UInt) {
let ranges = ByteRanges.rangesFor(contentLength: contentLength, rangeSize: rangeSize)
/// - ranges: the byte ranges to read the data from
init?(dataProvider: any DataProvider<Element>, ranges: [ClosedRange<UInt>]) {
guard !ranges.isEmpty else { return nil }
self.iterator = DataStreamIterator<Element>(dataProvider: dataProvider, ranges: ranges)
}
Expand Down
21 changes: 12 additions & 9 deletions Model/Utilities/WebKitHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,25 @@ final class KiwixURLSchemeHandler: NSObject, WKURLSchemeHandler {
}

let dataProvider: any DataProvider<URLContent>
let rangeSize: UInt // The size of the data chunks used for streaming data
let ranges: [ClosedRange<UInt>] // the list of ranges we should use to stream data
if metaData.isVideo, let directAccess = await directAccessInfo(for: url) {
dataProvider = ZimDirectContentProvider(directAccess: directAccess,
contentSize: metaData.size)
rangeSize = 2097152 // 2MB
ranges = ByteRanges.rangesFor(
contentLength: metaData.size,
rangeSize: 2097152 // 2MB
)
} else {
dataProvider = ZimContentProvider(for: url)
// set very high on purpose, until the zim file offset issue is solved
// @see: https://github.com/openzim/libzim/issues/886
// for the time being, this way we won't use chunks, but read the content in one piece
rangeSize = 209715200 // 200MB
// currently using the full range (from 0 to content size)
// this means we read the content in one piece
// once https://github.com/openzim/libzim/issues/886 is fixed
// we can stream compressed data "in chunks" as well
// to be done as part of: https://github.com/kiwix/kiwix-apple/issues/784
ranges = [0...metaData.size] // it's the full range
}

guard let dataStream = DataStream(dataProvider: dataProvider,
contentLength: metaData.size,
rangeSize: rangeSize)
guard let dataStream = DataStream(dataProvider: dataProvider, ranges: ranges)
else {
sendHTTP404Response(urlSchemeTask, url: url)
return
Expand Down

0 comments on commit 530c68a

Please sign in to comment.