This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[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() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TEST(ValuesTest, Overflow) { | |
Value::List parent; | |
parent.Append(1); | |
parent.Append(2); | |
parent[3]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | |
} |
NewerOlder