assetpack-transform-precomp2 0.3.0

Precomp2 file transforms for assetpack, with optional zstd and lzma wrapping.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
use assetpack_core::error::{Error, Result};

pub(crate) fn magic_match(head: &[u8]) -> bool {
  const PNG_MAGIC: &[u8] = b"\x89PNG\r\n\x1a\n";
  const GZIP_MAGIC: &[u8] = b"\x1f\x8b";
  const ZIP_MAGIC: &[u8] = b"PK\x03\x04";
  const PDF_MAGIC: &[u8] = b"%PDF";
  head.starts_with(PNG_MAGIC) || head.starts_with(GZIP_MAGIC) || head.starts_with(ZIP_MAGIC) || head.starts_with(PDF_MAGIC)
}

pub(crate) fn precomp2_guard<T>(context: &'static str, result: precomp2::Result<T>) -> Result<T> {
  result.map_err(|err| Error::Other(format!("precomp2 {context} failed: {err}")))
}