doc(examples): Fix errors
main() will still exist without a deflate cfg, it just won't do anything. Signed-off-by: Chris Hennick <4961925+Pr0methean@users.noreply.github.com>
This commit is contained in:
parent
855d57610c
commit
7355c51f93
1 changed files with 7 additions and 2 deletions
|
@ -1,20 +1,25 @@
|
||||||
#![cfg(feature = "_deflate-any")]
|
|
||||||
//! Write a huge file with lots of zeros, that should compress perfectly.
|
//! Write a huge file with lots of zeros, that should compress perfectly.
|
||||||
|
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|
||||||
use zip::write::SimpleFileOptions;
|
use zip::write::SimpleFileOptions;
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
if !cfg!(feature = "_deflate-any") {
|
||||||
|
return Err("Please enable one of the deflate features");
|
||||||
|
}
|
||||||
let args: Vec<_> = std::env::args().collect();
|
let args: Vec<_> = std::env::args().collect();
|
||||||
if args.len() < 2 {
|
if args.len() < 2 {
|
||||||
return Err(format!("Usage: {} <filename>", args[0]).into());
|
return Err(format!("Usage: {} <filename>", args[0]).into());
|
||||||
}
|
}
|
||||||
|
|
||||||
let filename = &*args[1];
|
let filename = &*args[1];
|
||||||
doit(filename)?;
|
#![] {
|
||||||
|
doit(filename)?;
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "_deflate-any")]
|
||||||
fn doit(filename: &str) -> zip::result::ZipResult<()> {
|
fn doit(filename: &str) -> zip::result::ZipResult<()> {
|
||||||
let file = std::fs::File::create(filename)?;
|
let file = std::fs::File::create(filename)?;
|
||||||
let mut zip = zip::ZipWriter::new(file);
|
let mut zip = zip::ZipWriter::new(file);
|
||||||
|
|
Loading…
Add table
Reference in a new issue