DataCompression icon indicating copy to clipboard operation
DataCompression copied to clipboard

Property if data is compressed

Open Vario opened this issue 5 years ago • 2 comments

Is there a way to check if a given set of data is compressed in any way? like data.isGzipped -> true or data.compression -> Compression.gzip || Compression.zip ,....

If not this would be a feature request

Vario avatar May 08 '19 11:05 Vario

Yes that seems plausible. Will try to get this into the next release. Just some notes: This will not be possible for all compression methods. Probably only gzip and zip, because the other steams don't have an identifying header.

mw99 avatar May 10 '19 03:05 mw99

extension Data {
    public var isGzipped :Bool {
        return self.starts(with: [0x1f,0x8b])
    }
}

You can use this code to check data is compressed with gzip

Kimentanm avatar Sep 02 '22 03:09 Kimentanm