mirror of
https://github.com/mii443/encrypt.git
synced 2025-08-22 15:05:33 +00:00
add file write function
This commit is contained in:
@ -38,6 +38,18 @@ pub const STD_FUNC: fn(
|
|||||||
) -> ExternalFuncReturn = |name, args, accept, reject, data| {
|
) -> ExternalFuncReturn = |name, args, accept, reject, data| {
|
||||||
let name = name.as_str();
|
let name = name.as_str();
|
||||||
match name {
|
match name {
|
||||||
|
"write" => {
|
||||||
|
let file_name = args[0].clone();
|
||||||
|
let content = args[1].clone();
|
||||||
|
let mut file =
|
||||||
|
std::fs::File::create(file_name.extract_text().unwrap().as_str()).unwrap();
|
||||||
|
file.write_all(content.extract_text().unwrap().as_bytes())
|
||||||
|
.unwrap();
|
||||||
|
ExternalFuncReturn {
|
||||||
|
status: ExternalFuncStatus::SUCCESS,
|
||||||
|
value: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
"length" => {
|
"length" => {
|
||||||
let vec = args[0].clone();
|
let vec = args[0].clone();
|
||||||
match vec {
|
match vec {
|
||||||
|
@ -54,4 +54,22 @@ impl Variable {
|
|||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn extract_text(&self) -> Option<String> {
|
||||||
|
match self {
|
||||||
|
Variable::Text { value } => Some(value.clone()),
|
||||||
|
Variable::Number { value } => Some(value.to_string()),
|
||||||
|
Variable::PureEncrypted { value } => Some(value.to_string()),
|
||||||
|
Variable::PairedEncrypted { value } => Some(value.to_string()),
|
||||||
|
Variable::U512 { value } => Some(value.to_string()),
|
||||||
|
Variable::Vec { value, .. } => {
|
||||||
|
let mut result = String::new();
|
||||||
|
for v in value {
|
||||||
|
result.push_str(&v.extract_text().unwrap());
|
||||||
|
}
|
||||||
|
Some(result)
|
||||||
|
}
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user