Guest User

Untitled

a guest
Jul 21st, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. // 2018-JUL-21 --- J.BENDOR --- 858-382-7570
  2.  
  3. #![feature(nll)]
  4. #![allow(dead_code)]
  5. #![allow(unused_parens)]
  6. #![allow(non_snake_case)]
  7. #![allow(non_upper_case_globals)]
  8.  
  9. use std::fs::OpenOptions;
  10. use std::io::Read;
  11. use std::str;
  12.  
  13. //**********************************************************************
  14. // reads a block of bytes into array --- returns zero on failure or EOF
  15. //**********************************************************************
  16. pub fn Read_Some_Bytes(aFilePath: &str, readLength: usize, byteVector: &mut Vec<u8>) -> usize {
  17. let mut open_options = OpenOptions::new();
  18.  
  19. open_options.read(true);
  20.  
  21. let maybe_file = open_options.open(aFilePath);
  22.  
  23. if maybe_file.is_err() {
  24. return 0;
  25. }
  26.  
  27. let mut src_file = maybe_file.unwrap();
  28.  
  29. byteVector.resize(readLength, 0);
  30.  
  31. let bytes_slice = &mut byteVector[0..readLength];
  32.  
  33. let num_bytes = src_file.read(bytes_slice).unwrap_or(0);
  34.  
  35. return num_bytes;
  36. }
  37.  
  38. fn main() {
  39. let mut read_txt = "COMPILE.FAILED";
  40.  
  41. {
  42. let mut bytes_vec: Vec<u8> = Vec::new();
  43.  
  44. // let mut read_txt = "READING.FAILED";
  45.  
  46. Read_Some_Bytes(r"E:\L14433.Molec.txt", 10, &mut bytes_vec);
  47.  
  48. let maybe_txt = str::from_utf8(&bytes_vec);
  49.  
  50. if maybe_txt.is_ok() {
  51. read_txt = maybe_txt.unwrap();
  52. }
  53.  
  54. println!("Read: ({})", read_txt.trim());
  55.  
  56. println!("ByeBye!");
  57. }
  58.  
  59. println!("{}", read_txt);
  60. }
Add Comment
Please, Sign In to add comment