Fix 'skip' support for binary streams (#5943)

This commit is contained in:
JT 2022-07-04 19:53:54 +12:00 committed by GitHub
parent c16d8f0d5f
commit 2da8310b11
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 4 deletions

View file

@ -93,18 +93,17 @@ impl Command for Skip {
let bytes = val.as_bytes();
if bytes.len() < remaining {
remaining -= bytes.len();
output.extend_from_slice(bytes)
//output.extend_from_slice(bytes)
} else {
output.extend_from_slice(&bytes[0..remaining]);
output.extend_from_slice(&bytes[remaining..]);
break;
}
}
Value::Binary { val: bytes, .. } => {
if bytes.len() < remaining {
remaining -= bytes.len();
output.extend_from_slice(&bytes)
} else {
output.extend_from_slice(&bytes[0..remaining]);
output.extend_from_slice(&bytes[remaining..]);
break;
}
}

View file

@ -1,2 +1,3 @@
mod skip_;
mod until;
mod while_;

View file

@ -0,0 +1,16 @@
use nu_test_support::{nu, pipeline};
#[test]
fn binary_skip() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
open sample_data.ods --raw |
skip 2 |
take 2 |
into int
"#
));
assert_eq!(actual.out, "772");
}