Preventing ioError with ArchiveStream.process

I am trying to use ArchiveStream.process on MacOS as outlined in the documentation here:

https://developer.apple.com/documentation/accelerate/decompressing_and_extracting_an_archived_directory

I have been able to successfully do the following:

  • Take objects and create Data objects
  • Create a UIDocument that is FileWrapper based
  • Compress the UIDocument as an .aar archive
  • Upload it to iCloud as a CKRecord
  • Download it as an .aar and decode it back to a directory
  • Decode the directory as individual data items and back to objects

The problem is that I sometimes can only download from iCloud once and have the decompression function - other times it may work two or three times but ultimately fails when trying to call ArchiveStream.process

The error reported by ArchiveStream.process is simply 'ioError' but on the console I see the following:

[0xa5063c00] Truncated block header (8/16 bytes read)
[0xa503d000] NOP received
[0xa5080400] processStream
[0xa7019000] decoder failed
[0xbd008c00] istream read error
[0xbd031c00] refill buffer
[0x90008000] archive stream read error (header)
[0xc8173800] stream cancelled

The test data I am using does not change so it does not appear to be related to what I am compressing.

But I am at a loss how to prevent the error.

This is IOS 17 running on MacOS (as iPad) and on IOS 17 devices.

In looking at this problem, I have determined that the file I have that is the generated archive, the uploaded archive, and the downloaded archive are all the same size.

I also was able to determine that the standard Archive Utility can successfully decompress a 'good' archive that doesn't crash the app, and won't decompress a 'bad' archive.

Lastly I am compressing and archiving the same data each time, so now I am wondering if there is a nuance in the compression I am missing.

So if I use .none for ArchiveCompression I do not see the crashing behavior:

        guard let compressStream = ArchiveByteStream.compressionStream(
            using: .none,           
            writingTo: writeFileStream) else {
            throw DocumentError.compressionStreamCreationFailed
        }

        // .lzfse, .zlib, .lzma, .lz4 all sporadically fail

Is there any compression type that reliably works with a UIDocument uploaded to iCloud?

Preventing ioError with ArchiveStream.process
 
 
Q