Fix examples and tests
This commit is contained in:
parent
fc20f9a20c
commit
e3b42c0c85
5 changed files with 17 additions and 15 deletions
|
@ -2,6 +2,8 @@
|
|||
|
||||
extern crate zip;
|
||||
|
||||
use std::old_io;
|
||||
|
||||
fn main()
|
||||
{
|
||||
let args = std::os::args();
|
||||
|
@ -11,7 +13,7 @@ fn main()
|
|||
return;
|
||||
}
|
||||
let fname = Path::new(&*args[1]);
|
||||
let file = std::io::File::open(&fname).unwrap();
|
||||
let file = old_io::File::open(&fname).unwrap();
|
||||
|
||||
let zipcontainer = zip::ZipReader::new(file).unwrap();
|
||||
|
||||
|
@ -23,7 +25,7 @@ fn main()
|
|||
let comment = &file.file_comment;
|
||||
if comment.len() > 0 { println!(" File comment: {}", comment); }
|
||||
|
||||
std::io::fs::mkdir_recursive(&outpath.dir_path(), std::io::USER_DIR).unwrap();
|
||||
old_io::fs::mkdir_recursive(&outpath.dir_path(), old_io::USER_DIR).unwrap();
|
||||
|
||||
if (&*file.file_name).ends_with("/") {
|
||||
create_directory(outpath);
|
||||
|
@ -34,17 +36,17 @@ fn main()
|
|||
}
|
||||
}
|
||||
|
||||
fn write_file(zipcontainer: &zip::ZipReader<std::io::File>, file: &zip::ZipFile, outpath: Path)
|
||||
fn write_file(zipcontainer: &zip::ZipReader<old_io::File>, file: &zip::ZipFile, outpath: Path)
|
||||
{
|
||||
let mut outfile = std::io::File::create(&outpath);
|
||||
let mut outfile = old_io::File::create(&outpath);
|
||||
let mut reader = zipcontainer.read_file(file).unwrap();
|
||||
std::io::util::copy(&mut reader, &mut outfile).unwrap();
|
||||
std::io::fs::chmod(&outpath, std::io::USER_FILE).unwrap();
|
||||
old_io::util::copy(&mut reader, &mut outfile).unwrap();
|
||||
old_io::fs::chmod(&outpath, old_io::USER_FILE).unwrap();
|
||||
}
|
||||
|
||||
fn create_directory(outpath: Path)
|
||||
{
|
||||
std::io::fs::mkdir_recursive(&outpath, std::io::USER_DIR).unwrap();
|
||||
old_io::fs::mkdir_recursive(&outpath, old_io::USER_DIR).unwrap();
|
||||
}
|
||||
|
||||
fn sanitize_filename(filename: &str) -> Path
|
||||
|
|
|
@ -11,7 +11,7 @@ fn main()
|
|||
return;
|
||||
}
|
||||
let fname = Path::new(&*args[1]);
|
||||
let file = std::io::File::open(&fname).unwrap();
|
||||
let file = std::old_io::File::open(&fname).unwrap();
|
||||
|
||||
let zipcontainer = zip::ZipReader::new(file).unwrap();
|
||||
|
||||
|
|
|
@ -22,23 +22,23 @@ fn main()
|
|||
fn doit(filename: &str) -> zip::result::ZipResult<()>
|
||||
{
|
||||
let path = Path::new(filename);
|
||||
let file = std::io::File::create(&path).unwrap();
|
||||
let file = std::old_io::File::create(&path).unwrap();
|
||||
|
||||
let mut zip = zip::ZipWriter::new(file);
|
||||
|
||||
try!(zip.start_file("test/", zip::CompressionMethod::Stored));
|
||||
|
||||
try!(zip.start_file("test/☃.txt", zip::CompressionMethod::Stored));
|
||||
try!(zip.write(b"Hello, World!\n"));
|
||||
try!(zip.write_all(b"Hello, World!\n"));
|
||||
|
||||
try!(zip.start_file("test/lorem_ipsum.txt", zip::CompressionMethod::Deflated));
|
||||
try!(zip.write(LOREM_IPSUM));
|
||||
try!(zip.write_all(LOREM_IPSUM));
|
||||
|
||||
try!(zip.finish());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
static LOREM_IPSUM : &'static [u8] = b"Lorem ipsum dolor sit amet, consectetur adipiscing elit. In tellus elit, tristique vitae mattis egestas, ultricies vitae risus. Quisque sit amet quam ut urna aliquet
|
||||
const LOREM_IPSUM : &'static [u8] = b"Lorem ipsum dolor sit amet, consectetur adipiscing elit. In tellus elit, tristique vitae mattis egestas, ultricies vitae risus. Quisque sit amet quam ut urna aliquet
|
||||
molestie. Proin blandit ornare dui, a tempor nisl accumsan in. Praesent a consequat felis. Morbi metus diam, auctor in auctor vel, feugiat id odio. Curabitur ex ex,
|
||||
dictum quis auctor quis, suscipit id lorem. Aliquam vestibulum dolor nec enim vehicula, porta tristique augue tincidunt. Vivamus ut gravida est. Sed pellentesque, dolor
|
||||
vitae tristique consectetur, neque lectus pulvinar dui, sed feugiat purus diam id lectus. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per
|
||||
|
|
|
@ -18,7 +18,7 @@ use bzip2::reader::BzDecompressor;
|
|||
/// // For demonstration purposes we read from an empty buffer.
|
||||
/// // Normally a File object would be used.
|
||||
/// let buf = [0u8; 128];
|
||||
/// let mut reader = std::io::BufReader::new(&buf);
|
||||
/// let mut reader = std::old_io::BufReader::new(&buf);
|
||||
///
|
||||
/// let zip = try!(zip::ZipReader::new(reader));
|
||||
///
|
||||
|
|
|
@ -29,11 +29,11 @@ enum GenericZipWriter<W>
|
|||
/// {
|
||||
/// // For this example we write to a buffer, but normally you should use a File
|
||||
/// let mut buf = [0u8; 65536];
|
||||
/// let w = std::io::BufWriter::new(&mut buf);
|
||||
/// let w = std::old_io::BufWriter::new(&mut buf);
|
||||
/// let mut zip = zip::ZipWriter::new(w);
|
||||
///
|
||||
/// try!(zip.start_file("hello_world.txt", zip::CompressionMethod::Stored));
|
||||
/// try!(zip.write(b"Hello, World!"));
|
||||
/// try!(zip.write_all(b"Hello, World!"));
|
||||
///
|
||||
/// // Optionally finish the zip. (this is also done on drop)
|
||||
/// try!(zip.finish());
|
||||
|
|
Loading…
Add table
Reference in a new issue