Post

Replies

Boosts

Views

Activity

Force Item Download in File Provider
I've file provider implementation where, in some cases, we must force download items, so they get materialized in local cache. I've used requestdownloadforitem based on following documentation https://developer.apple.com/documentation/fileprovider/nsfileprovidermanager/requestdownloadforitem(withidentifier:requestedrange:) I'm calling this within Extension code, but this does not trigger the download. How can I force file provider to download a file? cheers,
1
0
330
Aug ’24
Partial Download Support for macOS NSFileProvider Implementation
I've implemented a file provider for macos, and it works well. Now I'm trying to add partial download support in my implementation. however, it doesn't seem to work. As per documentation, I've implemented protocol NSFileProviderPartialContentFetching and its method func fetchPartialContents(for: NSFileProviderItemIdentifier, version: NSFileProviderItemVersion, request: NSFileProviderRequest, minimalRange: NSRange, aligningTo: Int, options: NSFileProviderFetchContentsOptions, completionHandler: (URL?, NSFileProviderItem?, NSRange, NSFileProviderMaterializationFlags, (any Error)?) -> Void) -> Progress Now, I'm testing my implementation, and I open a movie from my File Provider using VLC. I see that fetchPartialContents get a hit. I download requested range, and return it through completionHandler. However VLC gives a read error. here is my implementation of fetchPartialContents: private func align(range: NSRange, to alignment: Int) -> NSRange { let start = range.location - (range.location % alignment) let end = range.location + range.length let alignedEnd = ((end + alignment - 1) / alignment) * alignment let alignedLength = alignedEnd - start return NSRange(location: start, length: alignedLength) } unc fetchPartialContents(for itemIdentifier: NSFileProviderItemIdentifier, version requestedVersion: NSFileProviderItemVersion, request: NSFileProviderRequest, minimalRange requestedRange: NSRange, aligningTo alignment: Int, options: NSFileProviderFetchContentsOptions = [], completionHandler: @escaping (URL?, NSFileProviderItem?, NSRange, NSFileProviderMaterializationFlags, (any Error)?) -> Void) -> Progress { let alignedRange = align(range: requestedRange, to: alignment) let progress = Progress(totalUnitCount: 100) let data = downloadData(for: alignedRange) progress.completedUnitCount = 100; tempFileHandle = try FileHandle(forWritingTo: tempFileURL) tempFileHandle.seek(toFileOffset: UInt64(alignedRange.location)) tempFileHandle.write(data!) tempFileHandle.closeFile() let item = FileProviderItem(identifier: itemIdentifier,) completionHandler(tempFileURL, item, alignedRange, [], nil) } catch { completionHandler(nil, nil, alignedRange, [], error) } } I beleive I'm doing everhting correctly & as per documentation, but certainly there is something is wrong. Can someone help me about it? cheers,
2
0
417
Aug ’24