Skip to content

Instantly share code, notes, and snippets.

View adetaylor's full-sized avatar

Adrian Taylor adetaylor

View GitHub Profile
fn main() -> Result<()> {
let args = Args::parse();
let zipfile = File::open(args.zipfile)?;
let zipfile = CloneableFile::new(zipfile);
let zip = zip::ZipArchive::new(zipfile)?;
let file_count = zip.len();
println!("Zip has {} files", file_count);
(0..file_count).into_par_iter().for_each(|i| {
let mut myzip = zip.clone();
// extra 'use' statements omitted
fn main() -> Result<()> {
let args = Args::parse();
let mut zip = zip::ZipArchive::new(args.zipfile)?;
let file_count = zip.len();
println!("Zip has {} files", file_count);
(0..file_count).for_each(|i| {
let mut file = zip.by_index(i).expect("Unable to get file from zip");
if file.is_dir() {
#[derive(Clone)]
struct CloneableFile {
file: Arc<Mutex<File>>,
pos: u64,
// TODO determine and store this once instead of per cloneable file
file_length: Option<u64>,
}
impl CloneableFile {
use anyhow::Result;
use clap::Parser;
use std::fs::File;
/// Unzip all files within a zip file as quickly as possible.
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Args {
/// Zip file to unzip
#[arg(value_name = "FILE")]
#[gtest(RustValuesTest, TypeConfusion)]
fn test_type_confusion() {
let mut v = NewValueSlotForTesting();
let mut v = ValueSlotRef::from(&mut v);
let mut l = v.construct_list();
// l.set_integer_key("a", 3); // does not compile
}
#[gtest(RustValuesTest, DataRace)]
fn test_data_race() {
let json_decode_result = decode_some_hypothetical_json();
let mut site_descriptions = Vec::new();
// Convert JSON site descriptions into rendered site descriptions
site_descriptions.extend(
get_json_list_items(&json_decode_result).map(convert_json_to_site_description),
);
TEST(ValuesTest, DataRace) {
Value::List parent;
parent.Append(1);
parent.Append(2);
parent.Append(3);
for (auto it = parent.cbegin(); it != parent.cend(); it++) {
if (*it == 2) {
parent.reserve(100);
}
}
TEST(ValuesTest, UseAfterFree) {
Value parent(Value::Type::LIST);
parent.GetList().Append(Value(Value::Type::LIST));
Value& child = parent.GetList().back();
parent.Append("oops");
child.Append("oh dear");
}
TEST(ValuesTest, TypeConfusion) {
Value parent(Value::Type::LIST);
parent.GetList().Append(Value(Value::Type::LIST));
Value& child = parent.GetList().back();
child.SetKey("a", Value(3));
}
TEST(ValuesTest, Overflow) {
Value::List parent;
parent.Append(1);
parent.Append(2);
parent[3];
}