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 -ReadCount 0 does not respect -TotalCount #10707

Closed
mklement0 opened this issue Oct 5, 2019 · 5 comments · Fixed by #10749

Comments

@mklement0
Copy link
Contributor

commented Oct 5, 2019

Get-Content -ReadCount 0 is a convenient way to request that all lines be read at once, into an array and to have that array be output as a single object to the success stream.
If the intent is to read all lines into memory anyway, this can greatly speed up the command.

-TotalCount <n> allows you to limit the overall number of lines to be read from the file to a given number.

It's reasonable to expect that -ReadCount 0 also respects that number and therefore returns an <n>-element array.

Currently, -ReadCount 0 effectively ignores -TotalCount and always returns all lines in the file as an array.

By contrast, a specific number - e.g, -ReadCount 2 to read the file as a stream of 2-element arrays - does respect -TotalCount.

Steps to reproduce

1..10 > temp:/$pid.txt

(Get-Content temp:/$pid.txt -TotalCount 3 -ReadCount 0).Count | Should -Be 3

Remove-Item temp:/$pid.txt

Expected behavior

The test should pass.

Actual behavior

The test fails:

Expected 3, but got 10.

That is, all 10 lines were read, even though only 3 were requested with -TotalCount

Environment data

PowerShell Core 7.0.0-preview.4
@iSazonov

This comment has been minimized.

Copy link
Collaborator

commented Oct 7, 2019

Does -TotalCount 3 -ReadCount 2 work well?

@mklement0

This comment has been minimized.

Copy link
Contributor Author

commented Oct 7, 2019

Good question - yes, it does; I've added that fact to the OP.

@iSazonov

This comment has been minimized.

Copy link
Collaborator

commented Oct 7, 2019

In the case we have a bug. Simple for hacktoberfest.

@eugenesmlv

This comment has been minimized.

Copy link
Contributor

commented Oct 9, 2019

I would like to work on it.

@vexx32

This comment has been minimized.

Copy link
Collaborator

commented Oct 9, 2019

Have at it! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.