mw99 / DataCompression

Swift libcompression wrapper as an extension for the Data type (GZIP, ZLIB, LZFSE, LZMA, LZ4, deflate, RFC-1950, RFC-1951, RFC-1952)
Apache License 2.0
286 stars 57 forks source link

Property if data is compressed #19

Open Vario opened 5 years ago

Vario commented 5 years ago

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

mw99 commented 5 years ago

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.

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

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