let mut uncoded = Vec::new();
working_copy.read_file(&item.full_path, &mut uncoded)?;
let encoding = if tree_magic_mini::from_u8(&uncoded).starts_with("text/") {
let mut detector = EncodingDetector::new();
detector.feed(&uncoded, true);
let encoding = detector.guess(None, true);
debug!("guessed encoding = {:?}", encoding.name());
let (decoded, encoding, malformed) = encoding.decode(&uncoded);
debug!("final encoding = {:?}", encoding.name());
if !malformed {
self.rec.contents.append(&mut decoded.as_bytes().to_vec());
Some(encoding)
} else {
warn!("text file was malformed");
self.rec.contents.append(&mut uncoded);
None
}
} else {
self.rec.contents.append(&mut uncoded);
None
};