forked from extern/nushell
Support binary data to stdin of run-external (#4984)
* Add test for passing binary data through externals This change adds an ignored test to confirm that binary data is passed correctly between externals to be enabled in a later commit along with the fix. To assist in platform agnostic testing of binary data a couple of additional testbins were added to allow testing on `Value::Binary` inside `ExternalStream`. * Support binary data to stdin of run-external Prior to this change, any pipeline producing binary data (not detected as string) then feed into an external would be ignored due to run-external only supporting `Value::String` on stdin. This change adds binary stdin support for externals allowing something like this for example: 〉^cat /dev/urandom | ^head -c 1MiB | ^pv -b | ignore 1.00MiB This would previously output `0.00 B [0.00 B/s]` due to the data not being pushed to stdin at each stage.
This commit is contained in:
@ -169,12 +169,13 @@ impl ExternalCommand {
|
||||
|
||||
if let Ok(input) = input {
|
||||
for value in input.into_iter() {
|
||||
if let Value::String { val, span: _ } = value {
|
||||
if stdin_write.write(val.as_bytes()).is_err() {
|
||||
return Ok(());
|
||||
}
|
||||
} else {
|
||||
return Err(());
|
||||
let buf = match value {
|
||||
Value::String { val, .. } => val.into_bytes(),
|
||||
Value::Binary { val, .. } => val,
|
||||
_ => return Err(()),
|
||||
};
|
||||
if stdin_write.write(&buf).is_err() {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user