From 2da8310b116159617e16af36767764c6ebf6a379 Mon Sep 17 00:00:00 2001 From: JT <547158+jntrnr@users.noreply.github.com> Date: Mon, 4 Jul 2022 19:53:54 +1200 Subject: [PATCH] Fix 'skip' support for binary streams (#5943) --- crates/nu-command/src/filters/skip/skip_.rs | 7 +++---- crates/nu-command/tests/commands/skip/mod.rs | 1 + crates/nu-command/tests/commands/skip/skip_.rs | 16 ++++++++++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 crates/nu-command/tests/commands/skip/skip_.rs diff --git a/crates/nu-command/src/filters/skip/skip_.rs b/crates/nu-command/src/filters/skip/skip_.rs index 5cb285321f..202637dd64 100644 --- a/crates/nu-command/src/filters/skip/skip_.rs +++ b/crates/nu-command/src/filters/skip/skip_.rs @@ -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; } } diff --git a/crates/nu-command/tests/commands/skip/mod.rs b/crates/nu-command/tests/commands/skip/mod.rs index aa35de0702..3dacb42721 100644 --- a/crates/nu-command/tests/commands/skip/mod.rs +++ b/crates/nu-command/tests/commands/skip/mod.rs @@ -1,2 +1,3 @@ +mod skip_; mod until; mod while_; diff --git a/crates/nu-command/tests/commands/skip/skip_.rs b/crates/nu-command/tests/commands/skip/skip_.rs new file mode 100644 index 0000000000..e931be7195 --- /dev/null +++ b/crates/nu-command/tests/commands/skip/skip_.rs @@ -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"); +}