mirror of
https://github.com/nushell/nushell
synced 2024-12-27 21:43:09 +00:00
Remove stringification for binary values in save
command (#4428)
* Remove stringification for binary values in `save` * Fix typo and clippy warning
This commit is contained in:
parent
968ef1e953
commit
85d1a681c7
1 changed files with 30 additions and 30 deletions
|
@ -36,8 +36,6 @@ impl Command for Save {
|
|||
|
||||
let span = call.head;
|
||||
|
||||
let config = stack.get_config()?;
|
||||
|
||||
let path = call.req::<Spanned<String>>(engine_state, stack, 0)?;
|
||||
let arg_span = path.span;
|
||||
let path = Path::new(&path.item);
|
||||
|
@ -66,7 +64,7 @@ impl Command for Save {
|
|||
};
|
||||
|
||||
if let Some(ext) = ext {
|
||||
match engine_state.find_decl(format!("to {}", ext).as_bytes()) {
|
||||
let output = match engine_state.find_decl(format!("to {}", ext).as_bytes()) {
|
||||
Some(converter_id) => {
|
||||
let output = engine_state.get_decl(converter_id).run(
|
||||
engine_state,
|
||||
|
@ -75,7 +73,10 @@ impl Command for Save {
|
|||
input,
|
||||
)?;
|
||||
|
||||
let output = output.into_value(span);
|
||||
output.into_value(span)
|
||||
}
|
||||
None => input.into_value(span),
|
||||
};
|
||||
|
||||
match output {
|
||||
Value::String { val, .. } => {
|
||||
|
@ -94,25 +95,24 @@ impl Command for Save {
|
|||
}
|
||||
v => Err(ShellError::UnsupportedInput(v.get_type().to_string(), span)),
|
||||
}
|
||||
}
|
||||
None => {
|
||||
let output = input.collect_string("", &config)?;
|
||||
|
||||
if let Err(err) = file.write_all(output.as_bytes()) {
|
||||
return Err(ShellError::IOError(err.to_string()));
|
||||
}
|
||||
|
||||
Ok(PipelineData::new(span))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let output = input.collect_string("", &config)?;
|
||||
|
||||
if let Err(err) = file.write_all(output.as_bytes()) {
|
||||
match input.into_value(span) {
|
||||
Value::String { val, .. } => {
|
||||
if let Err(err) = file.write_all(val.as_bytes()) {
|
||||
return Err(ShellError::IOError(err.to_string()));
|
||||
}
|
||||
|
||||
Ok(PipelineData::new(span))
|
||||
}
|
||||
Value::Binary { val, .. } => {
|
||||
if let Err(err) = file.write_all(&val) {
|
||||
return Err(ShellError::IOError(err.to_string()));
|
||||
}
|
||||
|
||||
Ok(PipelineData::new(span))
|
||||
}
|
||||
v => Err(ShellError::UnsupportedInput(v.get_type().to_string(), span)),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue