Skip to content

feat(chunks, first, last, take, drop and skip): arg can now also be a filesize for binary - #18511

Merged
Bahex merged 10 commits into
nushell:mainfrom
Tyarel8:chunks-filesize
Jul 12, 2026
Merged

Bahex merged 10 commits into
nushell:mainfrom
Tyarel8:chunks-filesize

Conversation

@Tyarel8

@Tyarel8 Tyarel8 commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Description

chunks, first, last, take, drop and skip now takes oneof<int, filesize>, making using them with binary easier, previously you could just do chunks (10MiB | into int) but I think this change makes sense for binary data.

User-facing changes (Release notes)

drop now supports binary inputs as well

chunks, first, last, take, skip and drop can now be used with a filesize arguments

These commands can work on binary data, it only makes sense for them to work with not just int but filesize arguments as well:

# split compressed file into 10MiB chunks
open --raw file.7z
    | chunks 10MiB
    | enumerate 
    | each {|chunk| 
        let suffix = $chunk.index + 1 | fill -a right -c '0' -w 3
        $chunk.item
        | save $"file.7z.($suffix)"
    }

Additional notes

Needs to be merged from or rebased onto main after #18514 is merged.

@github-actions github-actions Bot added the A:parser Issues related to parsing label Jul 2, 2026
@Bahex

Bahex commented Jul 2, 2026

Copy link
Copy Markdown
Member

This is a really nice change, surprising that we didn't already have it.

Can you split the parser change into a separate PR? While it's also a nice change, it doesn't seem strictly necessary for this PR to work and I would prefer to have it separate since parser changes can have unexpected effects.

Other than that I have two suggestions:

  1. I wanted to see what other commands this could be applicable to and searched through existing commands:
    help commands
    | where {|cmd|
      $cmd.input_output
      | any {|io| $io.input has binary or $io.output has binary }
    }
    | where params.type has int
    | select name description params
    first, last, take and skip seem like great fits for this as well.
  2. Can you make it a (runtime) error to use filesize as the size when the input is not a byte stream or binary value?

@Tyarel8 Tyarel8 changed the title feat(chunks): chunk size can now also be a filesize feat(chunks, first, last, take, drop and skip): arg can now also be a filesize for binary Jul 3, 2026
@Tyarel8

Tyarel8 commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

@Bahex I have added the commands you suggested and also drop since it is in the same category. Also extracted the parser fix to #18514, but tests here will fail until it is merged.

@Bahex Bahex added status:wait-until-after-nushell-release notes:ready Indicates Ready for Release notes notes:additions Noted in "Additions" section and removed A:parser Issues related to parsing labels Jul 3, 2026
Bahex pushed a commit that referenced this pull request Jul 12, 2026
## Description
Makes the negative number or short flag detection work with `OneOff`
when the options can be negative numbers, necessary for the tests on
#18511 to pass.

## User-facing changes (Release notes)

Parameters with `int`, `float` and `number` types can be supplied
negative arguments:
```nushell
def foo [p: int] {
    $p
}

foo -2
# => -2
```

However this didn't work with parameters with types like `oneof<int,
...>`:
```nushell
def foo [p: <int, string>] {
    $p
}

foo -2
# => Error: nu::parser::unknown_flag
# => 
# =>   × The `foo` command doesn't have flag `-2`.
# =>    ╭─[repl_entry #1:3:6]
# =>  2 │ 
# =>  3 │ foo -2
# =>    ·      ┬
# =>    ·      ╰── unknown flag
# =>    ╰────
# =>   help: Use `--help` to see available flags
```

This is now fixed:
```nushell
def foo [p: <int, string>] {
    $p
}

foo -2
# => -2
```

## Additional notes
N/A
@Bahex
Bahex merged commit fb0039e into nushell:main Jul 12, 2026
14 checks passed
@github-actions github-actions Bot added this to the v0.115.0 milestone Jul 12, 2026
@Tyarel8
Tyarel8 deleted the chunks-filesize branch July 12, 2026 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

notes:additions Noted in "Additions" section notes:ready Indicates Ready for Release notes status:wait-until-after-nushell-release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants