| 236 | } |
| 237 | |
| 238 | pub fn detect_compression<P: AsRef<OsStr>>(path: P) -> std::io::Result<Option<Compression>> { |
| 239 | let mut p: Vec<u16> = path.as_ref().encode_wide().collect(); |
| 240 | p.push(0); |
| 241 | |
| 242 | let mut is_external: BOOL = 0; |
| 243 | let mut provider: ULONG = 0; |
| 244 | let mut file_info: _WOF_FILE_COMPRESSION_INFO_V1 = unsafe { std::mem::zeroed() }; |
| 245 | let mut len: ULONG = std::mem::size_of::<_WOF_FILE_COMPRESSION_INFO_V1>() as ULONG; |
| 246 | |
| 247 | let ret = unsafe { |
| 248 | WofIsExternalFile( |
| 249 | p.as_ptr(), |
| 250 | &mut is_external, |
| 251 | &mut provider, |
| 252 | &mut file_info as *mut _ as PVOID, |
| 253 | &mut len, |
| 254 | ) |
| 255 | }; |
| 256 | |
| 257 | if SUCCEEDED(ret) { |
| 258 | if is_external > 0 && provider == WOF_PROVIDER_FILE { |
| 259 | Ok(Compression::try_from(file_info.Algorithm).ok()) |
| 260 | } else { |
| 261 | Ok(None) |
| 262 | } |
| 263 | } else { |
| 264 | Err(std::io::Error::from_raw_os_error(HRESULT_CODE(ret))) |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | unsafe fn as_byte_slice<T: Sized + Copy>(p: &T) -> &[u8] { |
| 269 | std::slice::from_raw_parts((p as *const T) as *const u8, std::mem::size_of::<T>()) |