filecount 0.1.0

A modern high-performance open source file analysis library for automating localization tasks.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use std::error::Error;
use crate::{extract::Extract, zip_extensions::read_file_from_zip, xml_extensions::extract_text_from_nodes};

pub struct Xlsx;

impl Extract for Xlsx {
    fn can_extract(&self, buf: &[u8], _extension: Option<&str>) -> bool {
        infer::doc::is_xlsx(buf)
    }

    fn extract(&self, buf: &[u8]) -> Result<Vec<String>, Box<dyn Error>> {
        let shared_strings = read_file_from_zip(buf, "xl/sharedStrings.xml")?;
        let doc = roxmltree::Document::parse(&shared_strings)?;
        let texts = doc.root().descendants().filter(|n| n.has_tag_name("t")).collect();
        Ok(extract_text_from_nodes(texts))
    }
}