0

I have some data that I'm compressing & converting to a base 64 string and then sending to a server.

When i then fetch that data from the server and decompress it, the data usually decodes & decompresses fine, but for an occasional reading it will throw an error. Is there a way to find out more information about what part of the decompression process is failing?

Compressing:

let encodedCompressedReadings = try? (readings.toData() as NSData).compressed(using: .zlib).base64EncodedString()

Decompressing:

if let decodedCompressedReadings = Data(base64Encoded: encodedCompressedReadings) {
  do {
    let decodedDecompressedReadings = try (decodedCompressedReadings as NSData).decompressed(using: .zlib)
    ...
  } catch {
    print(error)                      // Error Domain=NSCocoaErrorDomain Code=5377 "(null)"
    print(error.localizedDescription) // The operation couldn’t be completed. (Cocoa error 5377.)
    print(NSDecompressionFailedError) // 5377
  }
}

  • Have you tried looking up the error code? – burnsi Nov 23 '22 at 18:42
  • Yes, that third print statement contains the variable name for the error code and apple's documentation doesn't really give any more information about it. I also can't seem to find anything helpful on stack overflow about it. https://developer.apple.com/documentation/foundation/nsdecompressionfailederror – Developer Extraordinare Nov 23 '22 at 18:46
  • The first thing to do is to check that data made it over correctly. For one of the error cases, compare byte-for-byte the compressed data, before Base64 encoding, with the result of Base64 decoding on the other end. – Mark Adler Nov 23 '22 at 19:44

0 Answers0