decode existing files
[?]
Dec 11, 2020, 9:57 AM
246V5TYIUL7CFN7G5Y7A35EEM6IJPN532ROEYVSM7Q4HCQSWPDBQCDependencies
- [2]
VMOYG7MKtext file decoding for new files - [3]
VO5OQW4WRemoving anyhow in libpijul - [4]
SXEYMYF7Fixing the bad changes in history (unfortunately, by rebooting).
Change contents
- edit in libpijul/src/working_copy/mod.rs at line 2
use chardetng::EncodingDetector;// use encoding_rs::Encoding; - edit in libpijul/src/working_copy/mod.rs at line 37
fn decode_file(&mut self, file: &str, buffer: &mut Vec<u8>) -> Result<(), Self::Error> {let mut uncoded = Vec::new();self.read_file(&file, &mut uncoded)?;let (mut decoded, 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 {(decoded.as_bytes().to_vec(), Some(encoding))} else {warn!("text file was malformed");(uncoded, None)}} else {(uncoded, None)};buffer.append(&mut decoded);Ok(())} - edit in libpijul/src/record.rs at line 3
use chardetng::EncodingDetector;// use encoding_rs::Encoding; - replacement in libpijul/src/record.rs at line 240
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};working_copy.decode_file(&item.full_path, &mut self.rec.contents)?; - replacement in libpijul/src/record.rs at line 392
.read_file(&item.full_path, &mut b).decode_file(&item.full_path, &mut b)