iocaine 3.0.0

The deadliest poison known to AI
Documentation
// SPDX-FileCopyrightText: 2025 Gergely Nagy
// SPDX-FileContributor: Gergely Nagy
//
// SPDX-License-Identifier: MIT

use std::fs::File;
use std::io::Read as _;

use super::SquashFS;

#[derive(Debug)]
pub struct GargleBargle(pub Vec<String>);

impl Default for GargleBargle {
    fn default() -> Self {
        let mut s = String::new();

        for file in SquashFS::iter() {
            let Some(data) = SquashFS::get(file.as_ref()) else {
                continue;
            };
            s.push_str(&String::from_utf8_lossy(data.data.as_ref()));
            s.push(' ');
        }

        Self(s.split_whitespace().map(str::to_owned).collect())
    }
}

impl GargleBargle {
    pub fn load_from_files<S: AsRef<str>>(files: &[S]) -> Result<Self, std::io::Error> {
        if files.is_empty() {
            tracing::error!("Wordlist empty, cannot load");
            return Err(std::io::Error::new(
                std::io::ErrorKind::InvalidInput,
                "Empty wordlist",
            ));
        }
        let mut s = String::new();
        for source in files {
            let mut f = File::open(source.as_ref())?;
            f.read_to_string(&mut s)?;
            s.push(' ');
        }

        Ok(Self(s.split_whitespace().map(str::to_owned).collect()))
    }
}