Skip to content

Get-Content with -AsByteStream -ReadCount X -Raw should return byte arrays #21510

Closed

Description

@rhubarb-geek-nz

Prerequisites

Steps to reproduce

Get-Content with -AsByteStream, -Raw and -ReadCount should return list of byte []

Simple script below

Set-Content -LiteralPath 'foo.bar' -Value 'foobar' -NoNewLine

Get-ChildItem -LiteralPath 'foo.bar'

$foo = Get-Content -LiteralPath 'foo.bar' -AsByteStream

$foo.GetType().Name
$foo[0].GetType().Name
$foo.Count
$foo[0].Count

$foo = Get-Content -LiteralPath 'foo.bar' -AsByteStream -ReadCount 3

$foo.GetType().Name
$foo[0].GetType().Name
$foo.Count
$foo[0].Count
$foo[1].Count

$foo = Get-Content -LiteralPath 'foo.bar' -AsByteStream -ReadCount 3 -Raw

$foo.GetType().Name
$foo[0].GetType().Name
$foo.Count
$foo[0].Count
$foo[1].Count

Expected behavior

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---          21/04/2024    03:03              6 foo.bar
Object[]
Byte
6
1
Object[]
Object[]
2
3
3
Object[]
Byte[]
2
3
3

Actual behavior

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---          21/04/2024    03:03              6 foo.bar
Object[]
Byte
6
1
Object[]
Object[]
2
3
3
Object[]
Byte[]
1
6
0

Error details

no errors

Environment data

Name                           Value
----                           -----
PSVersion                      7.4.2
PSEdition                      Core
GitCommitId                    7.4.2
OS                             Microsoft Windows 10.0.22631
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

just the above text will suffice

Activity

  1. mklement0 commented on Apr 21, 2024

    @mklement0
    Contributor

    I support this feature request, but let me add some context:

    • If -ReadCount is specified, -Raw is ignored (which is unfortunate, and arguably a bug).

    • -Raw in combination with -AsByteStream - but without -ReadCount - does emit a [byte[]] array, but it invariably means reading the whole input file into memory.

    • -ReadCount - wich currently emits [object[]] arrays - should:

      • emit [string[]] arrays by default
      • if -AsByteStream is also specified, should emit [byte[]] arrays

    In other words: when "chunking" is requested via -ReadCount a strongly typed array should be returned, which helps performance, especially in v7.4+ with -AsByeStream, which then allows directly outputting chunked byte data to an external (native) program (which only works with [byte[]] arrays, not with [object[]] arrays).

    This is technically a breaking change, but most likely one that falls into bucket 3.

  2. jdhitsolutions commented on Aug 8, 2024

    @jdhitsolutions
    Collaborator

    Added for the Cmdlet WG to review

  3. JamesWTruher commented on Sep 4, 2024

    @JamesWTruher
    Collaborator

    The WG discussed this and while we recognize this behavior may not be consistent with expectations, we believe that this does not meet the bar for return on engineering investment to make any changes.

  4. added
    Resolution-Won't FixThe issue won't be fixed, possibly due to compatibility reason.
    and removed
    Needs-TriageThe issue is new and needs to be triaged by a work group.
    on Sep 4, 2024
  5. added
    WG-ReviewedA Working Group has reviewed this and made a recommendation
    and removed
    WG-NeedsReviewNeeds a review by the labeled Working Group
    on Sep 4, 2024
  6. mklement0 commented on Sep 4, 2024

    @mklement0
    Contributor

    does not meet the bar for return on engineering investment

    Isn't the proper resolution then to assign the Up-for-grabs label?

  7. microsoft-github-policy-service commented on Sep 5, 2024

    @microsoft-github-policy-service
    Contributor

    This issue has been marked as won't fix and has not had any activity for 1 day. It has been closed for housekeeping purposes.

  8. microsoft-github-policy-service commented on Sep 5, 2024

    @microsoft-github-policy-service
    Contributor

    📣 Hey rhubarb-geek-nz, how did we do? We would love to hear your feedback with the link below! 🗣️

    🔗 https://aka.ms/PSRepoFeedback

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

    Resolution-Won't FixThe issue won't be fixed, possibly due to compatibility reason.WG-Cmdletsgeneral cmdlet issuesWG-ReviewedA Working Group has reviewed this and made a recommendation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions