Fix tests and examples

This commit is contained in:
Mathijs van de Nes 2015-02-24 16:16:08 +01:00
parent bb89f577c5
commit 6d2a63e406
3 changed files with 20 additions and 16 deletions

View file

@ -1,8 +1,9 @@
#![feature(old_path, old_io, env)]
#![feature(old_path, io, fs, env)]
extern crate zip;
use std::old_io;
use std::io;
use std::fs;
fn main()
{
@ -13,7 +14,7 @@ fn main()
return;
}
let fname = Path::new(&*args[1]);
let file = old_io::File::open(&fname).unwrap();
let file = fs::File::open(&fname).unwrap();
let zipcontainer = zip::ZipReader::new(file).unwrap();
@ -25,7 +26,7 @@ fn main()
let comment = &file.file_comment;
if comment.len() > 0 { println!(" File comment: {}", comment); }
old_io::fs::mkdir_recursive(&outpath.dir_path(), old_io::USER_DIR).unwrap();
fs::create_dir_all(&outpath.dir_path()).unwrap();
if (&*file.file_name).ends_with("/") {
create_directory(outpath);
@ -36,17 +37,16 @@ fn main()
}
}
fn write_file(zipcontainer: &zip::ZipReader<old_io::File>, file: &zip::ZipFile, outpath: Path)
fn write_file(zipcontainer: &zip::ZipReader<fs::File>, file: &zip::ZipFile, outpath: Path)
{
let mut outfile = old_io::File::create(&outpath);
let mut outfile = fs::File::create(&outpath).unwrap();
let mut reader = zipcontainer.read_file(file).unwrap();
old_io::util::copy(&mut reader, &mut outfile).unwrap();
old_io::fs::chmod(&outpath, old_io::USER_FILE).unwrap();
io::copy(&mut reader, &mut outfile).unwrap();
}
fn create_directory(outpath: Path)
{
old_io::fs::mkdir_recursive(&outpath, old_io::USER_DIR).unwrap();
fs::create_dir_all(&outpath).unwrap();
}
fn sanitize_filename(filename: &str) -> Path

View file

@ -1,4 +1,6 @@
#![feature(old_path, old_io, env)]
#![feature(old_path, io, fs, env)]
use std::io::prelude::*;
extern crate zip;
@ -11,7 +13,7 @@ fn main()
return;
}
let fname = Path::new(&*args[1]);
let file = std::old_io::File::open(&fname).unwrap();
let file = std::fs::File::open(&fname).unwrap();
let zipcontainer = zip::ZipReader::new(file).unwrap();
@ -21,7 +23,7 @@ fn main()
None => { println!("File test/lorem_ipsum.txt not found"); return }
};
let data = zipcontainer.read_file(file).unwrap().read_to_end().unwrap();
let contents = String::from_utf8(data).unwrap();
let mut contents = String::new();
zipcontainer.read_file(file).unwrap().read_to_string(&mut contents).unwrap();
println!("{}", contents);
}

View file

@ -17,10 +17,12 @@ use ioconverter::IoConverter;
/// ```
/// fn doit() -> zip::result::ZipResult<()>
/// {
/// use std::io::prelude::*;
///
/// // For demonstration purposes we read from an empty buffer.
/// // Normally a File object would be used.
/// let buf = [0u8; 128];
/// let mut reader = std::old_io::BufReader::new(&buf);
/// let buf: &[u8] = &[0u8; 128];
/// let mut reader = std::io::Cursor::new(buf);
///
/// let zip = try!(zip::ZipReader::new(reader));
///
@ -28,7 +30,7 @@ use ioconverter::IoConverter;
/// {
/// println!("Filename: {}", file.file_name);
/// let mut file_reader = try!(zip.read_file(file));
/// let first_byte = try!(file_reader.read_byte());
/// let first_byte = try!(file_reader.bytes().next().unwrap());
/// println!("{}", first_byte);
/// }
/// Ok(())