0

When using decompressed(using:) method of NSData I have to provide a NSData.CompressionAlgorithm to uncompress the data.
Is there a way to detect the compression method of a NSData object so I don't have to know which method was used for compressing?

Mike Nathas
  • 1,247
  • 2
  • 11
  • 29
  • 2
    Why would you need to detect if you already know which one you have used? – Leo Dabus Dec 09 '21 at 14:12
  • I don't know which Algorithm is used in my NSData object. As I am handling with multiple Algorithms I have to check for each every time I want to access these data – Mike Nathas Dec 09 '21 at 14:18
  • 1
    It seems that some of the format might have a "start of file" proper to them, with no guarantee though that the file is fully compliant. A little like a JPEG starts with `FFD8FF`... I'm not sure at all, I'm just wondering if it could be a search start... – Larme Dec 09 '21 at 14:21
  • You are the one who compressed the data. Just keep that info for later usage. – Leo Dabus Dec 09 '21 at 23:38
  • I did not compress the data (I never wrote this) I am importing NSData from files where I do not know if or which algorithm was used! – Mike Nathas Dec 10 '21 at 04:37
  • @MikeNathas ..so can you make sense of the (decomp.) data and trial various compression methods to see which returns sensible, uncompressed data? – ATV Dec 10 '21 at 09:00
  • Does this answer your question? [How to detect type of compression used on the file? (if no file extension is specified)](https://stackoverflow.com/questions/19120676/how-to-detect-type-of-compression-used-on-the-file-if-no-file-extension-is-spe) – oleksii Dec 10 '21 at 13:40
  • In general a good idea, but as always Apple is cooks their own soup and they don't use the official implementation but uses their own custom ones. I'll export a bit data, maybe there is a pattern but I think the only solution will be just try out every algorithm until valid data is there. – Mike Nathas Dec 10 '21 at 15:58

0 Answers0