Skip to content

open --raw with multiple files splits contents into chunks of 8KB #10027

Done

Description

@tertsdiepraam

Describe the bug or feature

If open --raw is used with a multiple files, the files are chunked into chunks of 8192 bytes (8KB). This seems like unintuitive behaviour. The behaviour I expected was to get was a list with an element per file.

Expected behaviour

$ open --raw Cargo.toml LICENSE | str length
╭───┬───────╮
│ 0 │ 25159 │
│ 1 │  1069 │
╰───┴───────╯

Actual behaviour

$ open --raw Cargo.toml LICENSE | str length
╭───┬──────╮
│ 0 │ 8192 │
│ 1 │ 8192 │
│ 2 │ 4694 │
│ 3 │ 1069 │
╰───┴──────╯

where the first 3 elements are the contents of Cargo.toml and the last is LICENSE.

The 8KB probably comes from the use of a BufReader, which has 8KB as its default capacity.

Activity

  1. added
    status:needs-triage
    A:std-library
    on Aug 16, 2023
  2. removed
    A:std-library
    on Aug 16, 2023
  3. added
    category:bug
    A:file-system
    A:streaming
    A:redirection-pipe
    and removed
    status:needs-triage
    on Aug 16, 2023
  4. sophiajt commented on Aug 16, 2023

    @sophiajt
    Contributor

    👍 that we should stream out. The BufReader may be fine if other parts of the system expect the whole stream to be understood as one value. It seems that we're treating each chunk from the stream separately.

  5. TheLostLambda commented on Apr 9, 2026

    @TheLostLambda
    Contributor

    This is a wild bug that I think I've just run into as well — no --raw needed for these files (I'd imagine because Nushell doesn't natively read .jsonl):

    ❯ open assembly_data_report1.jsonl assembly_data_report2.jsonl | str length
    ╭───┬──────╮
    │ 0 │ 4004 │
    │ 1 │ 8192 │
    │ 2 │  560 │
    ╰───┴──────╯

    It's splitting the second file there, but if you load one file at a time:

    ❯ open assembly_data_report2.jsonl | str length
    8752
    
    # Or even:
    
    ❯ [assembly_data_report1.jsonl assembly_data_report2.jsonl] | each { open | str length}
    ╭───┬──────╮
    │ 0 │ 4004 │
    │ 1 │ 8752 │
    ╰───┴──────╯
  6. amandalewis1231-lgtm commented on Apr 9, 2026

    @amandalewis1231-lgtm
  7. TheLostLambda commented on Apr 9, 2026

    @TheLostLambda
    Contributor

    I'm being chased around GitHub by bots... So feel free to hide the above comment as spam... I nearly have a PR ready.

  8. fdncred commented on Apr 9, 2026

    @fdncred
    Contributor

    if you search the code base for 8192 you'll find that it's a buffer size and an output chunk size. i suspect this has something to do with the problem. sophia talks about needing to stream above.

  9. TheLostLambda commented on Apr 15, 2026

    @TheLostLambda
    Contributor

    For everyone here, to get a final check on some chatting we were doing on the Discord, would people be okay with open --raw Cargo.toml LICENSE returning a single, concatenated string (like it returns concatenated tables), and if you want the current behaviour (returning a list of strings, but without the chunking, which I've identified the source of) you can pipe a list in? Like [Cargo.toml LICENSE] | open.

    By default then, --raw or not, open x y acts just like cat x y, sticking things together, and if you want a list out, you can give it a list in: [x y] | open. I feel something like that would make open more consistent and predictable!

    Let me know what you think!

  10. fdncred commented on Apr 15, 2026

    @fdncred
    Contributor

    This is what I said in Discord already. Working like cat is not the goal. Working like nushell is the goal. 4 works like 1 except that it gets passed through from ext.

    Trying to help answer your question here so you can make some progress.

    1. open -raw file1 file2 file3 should produce a raw byte stream. i think this is similar to cat
    2. open file.recognized_extension should work the way it does today except not be hampered by 8192 bytes truncating things. streaming would be great.
    3. for now, open file1.recognized_extension file2.recognized_extension should work like it does now in that test. you might find that PR that works on csv/tsv specifically to understand how it may change.
    4. i think open file1.unrecognized_ext file2.unrecognized_ext should probably work like it does now except for any 8192 problems, which is group by file and produce a table so index 0 would be the first file and index 1 would be the second file.
  11. TheLostLambda commented on Apr 15, 2026

    @TheLostLambda
    Contributor

    I agree that working like Nushell should indeed be the goal, I just find it a bit inconsistent for your example 1 to return one stream, 2 to return one parsed table, 3 to return one parsed, joined table, and for 4 to return multiple strings / streams.

    But I may not fully understand what you mean by:

    4 works like 1 except that it gets passed through from ext.

    As I understand, that's not what you're suggesting? You're suggesting that 1 concatenates the strings, but 4 doesn't? That seems like an additional difference on top of the from ext difference?

    The pattern seems to be open returns one object, but that's broken for 4 only. I think I'd find it odd for open LICENSE LICENSE to return a list of two strings, but open Cargo.toml Cargo.toml to return a single table, hence my suggestion above. The [x y] | open syntax has nushell precedence with things like [x y] | str length in which str length is mapped over the piped-in list.

    I'm also open to making things consistent in the opposite direction, where open always returns a list with one item for each file passed to it (identical to how [Cargo.toml, LICENSE] | each { open } works currently), but I do think that's a bit less helpful and at that point would almost favor dropping the ability of open to take multiple files in argument position entirely.

    With that all said though, if others disagree and would prefer @fdncred 's outlined behaviour, then that's alright — anything is better than the current buggy behaviour!

  12. fdncred commented on Apr 15, 2026

    @fdncred
    Contributor

    TBH, I could live with it either way. I just wonder if we're arguing about something that people really don't care about. If 4 outputs 1 item or multiple grouped items really doesn't make much difference to me. It just seems like outputting multiple grouped items is more nushell-y. The bigger problem is the 8192 issue.

  13. TheLostLambda commented on Apr 15, 2026

    @TheLostLambda
    Contributor

    @fdncred I think that's a fair point — I'll start on the 8192 issue and see if the code makes one path significantly easier or harder than the other!

    I've got some technical implementation questions, but I'll ask those on Discord!

  14. kronberger-droid commented on Nov 14, 2026

    @kronberger-droid
    Contributor

    Still reproduces on 0.117 with files of 25159 and 1069 bytes:

    open --raw big.txt small.txt | str length   # [8192, 8192, 8192, 583, 1069]
    
  15. added a commit that references this issue on Nov 24, 2026
    9d87334
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A:file-systemA:redirection-pipeA:streamingcategory:bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions