Guest User

Untitled

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