python_assembler/formats/pyc/
mod.rs

1use crate::program::{PythonProgram, PythonVersion};
2use gaia_types::{
3    helpers::{open_file, Url},
4    GaiaError,
5};
6use std::{
7    fmt::Debug,
8    io::{BufReader, Read},
9    path::Path,
10};
11
12pub mod reader;
13pub mod view;
14pub mod writer;
15
16#[derive(Clone, Debug, PartialEq, Eq)]
17pub struct PycReadConfig {
18    pub url: Option<Url>,
19    pub version: PythonVersion,
20}
21
22#[derive(Copy, Clone, Debug, PartialEq, Eq)]
23pub struct PycWriteConfig {}
24
25impl Default for PycReadConfig {
26    fn default() -> Self {
27        Self { url: None, version: PythonVersion::Unknown }
28    }
29}
30
31pub fn pyc_read_path(path: &Path) -> Result<PythonProgram, GaiaError> {
32    let (file, url) = open_file(path)?;
33    let mut config = PycReadConfig::default();
34    config.url = Some(url);
35    let mut reader = config.as_reader(BufReader::new(file));
36    reader.read_to_end()?;
37    reader.view.to_program(&config).result
38}