Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 2018-JUL-21 --- J.BENDOR --- 858-382-7570
- #![feature(nll)]
- #![allow(dead_code)]
- #![allow(unused_parens)]
- #![allow(non_snake_case)]
- #![allow(non_upper_case_globals)]
- use std::str;
- use std::io::Read;
- use std::fs::OpenOptions;
- //**********************************************************************
- // reads a block of bytes into array --- returns zero on failure or EOF
- //**********************************************************************
- pub fn Read_Some_Bytes ( aFilePath : &str,
- readLength : usize,
- byteVector : &mut Vec<u8> ) -> usize
- {
- let mut open_options = OpenOptions::new();
- open_options.read(true);
- let maybe_file = open_options.open(aFilePath);
- if maybe_file.is_err()
- {
- return 0;
- }
- let mut src_file = maybe_file.unwrap();
- byteVector.resize( readLength, 0 );
- let bytes_slice = &mut byteVector [ 0 .. readLength ];
- let num_bytes = src_file.read( bytes_slice ).unwrap_or(0);
- return num_bytes;
- }
- fn main()
- {
- let mut read_txt = "COMPILE.FAILED";
- let mut bytes_vec : Vec<u8> = Vec::new();
- // let mut read_txt = "READING.FAILED";
- Read_Some_Bytes(r"E:\L14433.Molec.txt", 10, &mut bytes_vec);
- let maybe_txt = str::from_utf8( &bytes_vec );
- if maybe_txt.is_ok()
- {
- read_txt = maybe_txt.unwrap();
- }
- println!( "Read: ({})", read_txt.trim() );
- println!( "ByeBye!" );
- }
Add Comment
Please, Sign In to add comment