Return a list of files that are included.
This commit is contained in:
45
src/files.rs
45
src/files.rs
@@ -1,21 +1,43 @@
|
||||
use std::fs;
|
||||
pub fn read_file(file_name: &str, depth: u8) -> Vec<u8>
|
||||
extern crate notify;
|
||||
use notify::{
|
||||
DebouncedEvent,
|
||||
RecommendedWatcher,
|
||||
RecursiveMode,
|
||||
Watcher
|
||||
};
|
||||
use std::
|
||||
{
|
||||
fs,
|
||||
time::Duration,
|
||||
path::Path,
|
||||
sync::mpsc::channel,
|
||||
};
|
||||
|
||||
pub fn read_file(file_name: &str, depth: u8) ->
|
||||
(
|
||||
Vec<u8>,
|
||||
Vec<String>,
|
||||
)
|
||||
{
|
||||
if let Ok(file_contents) = fs::read_to_string(format!("root/{}",file_name))
|
||||
{
|
||||
let bytes = encode_npon(&file_contents, depth);
|
||||
return bytes
|
||||
let (bytes, mut file_list) = encode_npon(&file_contents, depth);
|
||||
return (bytes, file_list)
|
||||
}
|
||||
return vec![]
|
||||
|
||||
return (vec![], vec![])
|
||||
}
|
||||
|
||||
fn encode_npon(file_contents: &String, depth: u8) -> Vec<u8>
|
||||
fn encode_npon(file_contents: &String, depth: u8) ->
|
||||
(
|
||||
Vec<u8>,
|
||||
Vec<String>,
|
||||
)
|
||||
{
|
||||
let mut bytes: Vec<u8> = vec![];
|
||||
let mut file_list: Vec<String> = vec![];
|
||||
if depth > 63 {
|
||||
println!("Depth level safety reached (63), recursion error suspected");
|
||||
return vec![];
|
||||
return (vec![], file_list);
|
||||
}
|
||||
if depth == 0 {
|
||||
bytes.push(01);
|
||||
@@ -117,7 +139,9 @@ fn encode_npon(file_contents: &String, depth: u8) -> Vec<u8>
|
||||
{
|
||||
58 =>
|
||||
{
|
||||
let new_bytes = read_file(&file_contents[index_flag..index], depth+1);
|
||||
file_list.push((&file_contents[index_flag..index.clone()]).to_string());
|
||||
let (new_bytes, mut new_file_list) = read_file(&file_contents[index_flag..index], depth+1);
|
||||
file_list.append(&mut new_file_list);
|
||||
for byte in new_bytes.iter()
|
||||
{
|
||||
bytes.push(*byte);
|
||||
@@ -135,5 +159,6 @@ fn encode_npon(file_contents: &String, depth: u8) -> Vec<u8>
|
||||
bytes.push(02);
|
||||
}
|
||||
|
||||
return bytes
|
||||
return (bytes, file_list)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user