8 releases (breaking)

0.8.0 Mar 26, 2024
0.7.0 Mar 15, 2024
0.6.0 Mar 13, 2024
0.5.0 Mar 7, 2024
0.1.0 Nov 30, 2023

#149 in Compression

Download history 9/week @ 2024-02-19 170/week @ 2024-02-26 343/week @ 2024-03-04 274/week @ 2024-03-11 25/week @ 2024-03-18 113/week @ 2024-03-25 81/week @ 2024-04-01

505 downloads per month
Used in 2 crates (via willbe)

MIT license

13KB
124 lines

Module :: crates_tools

experimentalrust-statusdocs.rsOpen in Gitpod discord

Tools to analyse crate files.

A crate file is a package of Rust source code that can be downloaded from crates.io, the official Rust package registry. A crate file has the extension .crate and contains a compressed archive of the source code and other files needed to compile and run the crate.

crate_tools allows you to download and read and decode the .crate files. You can then use the CrateArchive struct to list and access the contents of the file as bytes.

This crate is useful for developers who want to inspect and analyze Rust crates. Some possible use cases are:

  • Compare the source code of different versions of a crate to see what has changed;
  • Search for leftover confidential data before publishing;
  • Analyze the size of packed files.

Sample :: show crate content

use crates_tools::*;

fn main()
{
  #[ cfg( feature = "enabled" ) ]
  {
    // download a package with specific version from `crates.io`
    let crate_archive = CrateArchive::download_crates_io( "test_experimental_c", "0.1.0" ).unwrap();

    for path in crate_archive.list()
    {
      // take content from a specific file from the archive
      let bytes = crate_archive.content_bytes( path ).unwrap();
      let string = std::str::from_utf8( bytes ).unwrap();

      println!("# {}\n```\n{}```", path.display(), string);
    }
  }
}

To add to your project

cargo add crates_tools

Try out from the repository

git clone https://github.com/Wandalen/wTools
cd wTools/module/move/crates_tools
cargo r --example show_crate_content

Dependencies

~2–12MB
~132K SLoC