Michael-F-Bryan / include_dir

The logical evolution of the include_str macro for embedding a directory tree into your binary.
https://michael-f-bryan.github.io/include_dir
MIT License
319 stars 36 forks source link

Add a feature to compress input files and then lazily decompress it #80

Open LordRatte opened 2 years ago

LordRatte commented 2 years ago

A suggested solution for #14

LordRatte commented 2 years ago

To visualise how it works, let's take an example of the generated, intermediate code.

...

static PROJECT_DIR: Dir =
    include_dir::Dir::new("",
        &[include_dir::DirEntry::File(include_dir::File::new("a",
                            b"12345678910\n12345678910\n12345678910\n12345678910\n12345678910\n12345678910\n12345678910\n12345678910\n12345678910\n12345678910\n"))]);

fn main() {
    PROJECT_DIR.extract(Path::new("./o")).unwrap();
}

Now becomes the following with the feature turned on

...

static PROJECT_DIR: Dir = include_dir::Dir::new(
    "",
    &[include_dir::DirEntry::File(include_dir::File::new(
        "a",
        b"\xcf12345678910\n\x0c\x00Y\x00",
    ))],
);

fn main() {
    PROJECT_DIR.extract(Path::new("./o")).unwrap();
}