Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
5 tasks done
rhubarb-geek-nz opened this issue Apr 21, 2024 · 2 comments
Open
5 tasks done
Labels
Needs-Triage The issue is new and needs to be triaged by a work group. WG-Cmdlets general cmdlet issues WG-NeedsReview Needs a review by the labeled Working Group

Comments

@rhubarb-geek-nz
Copy link

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

@rhubarb-geek-nz rhubarb-geek-nz added the Needs-Triage The issue is new and needs to be triaged by a work group. label Apr 21, 2024
@rhubarb-geek-nz
Copy link
Author

rhubarb-geek-nz commented Apr 21, 2024

Compare with proof of concept Split-Content

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

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

Gives list of byte arrays

Object[]
Byte[]
2
3
3

@mklement0
Copy link
Contributor

mklement0 commented Apr 21, 2024

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.

@SteveL-MSFT SteveL-MSFT added WG-Cmdlets general cmdlet issues WG-NeedsReview Needs a review by the labeled Working Group labels Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs-Triage The issue is new and needs to be triaged by a work group. WG-Cmdlets general cmdlet issues WG-NeedsReview Needs a review by the labeled Working Group
Projects
None yet
Development

No branches or pull requests

3 participants