detect_compression

Function detect_compression 

Source
pub fn detect_compression(content: &[u8]) -> Compression
Expand description

Detects the compression format of binary content.

Examines the magic bytes at the start of the content to determine the compression format. This is useful for automatically decompressing downloaded descriptors.

§Arguments

  • content - The binary content to examine

§Returns

The detected Compression format, or Compression::Plaintext if no compression is detected or the content is too short.

§Example

use stem_rs::descriptor::{detect_compression, Compression};

// Gzip magic bytes
let gzip_content = &[0x1f, 0x8b, 0x08, 0x00];
assert_eq!(detect_compression(gzip_content), Compression::Gzip);

// Plain text
let plain = b"router example";
assert_eq!(detect_compression(plain), Compression::Plaintext);