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-contentFast is opening files read-write #1

Open
johnanson opened this issue May 13, 2019 · 4 comments
Open

get-contentFast is opening files read-write #1

johnanson opened this issue May 13, 2019 · 4 comments

Comments

@johnanson
Copy link

I'm pretty sure that:
$File = New-Object System.IO.StreamReader -Argument $PathName
opens the file read-write, which will fail if another process has the file open, not allowing writing.

This should open the file readonly as long as reading is allowed by the process that has the file open:
$fs = [IO.File]::Open($PathName, [IO.FileMode]::Open, [IO.FileAccess]::Read, [IO.FileShare]::ReadWrite)
$File = New-Object System.IO.StreamReader -Argument $fs

@martin9700
Copy link
Owner

martin9700 commented May 14, 2019

Interesting, I look forward to your pull request! Could you include before and after times on a really big text file? Maybe 10,000 lines or something? I think that would be really interesting to see.

@martin9700
Copy link
Owner

Interesting read on MSDN (what I can make of it). It's all about being a reader, but then lower down mentions it can use the write method. Sheesh, make up your mind! :)

StreamReader is designed for character input in a particular encoding, whereas the Stream class is designed for byte input and output. Use StreamReader for reading lines of information from a standard text file.
The Read(Char[], Int32, Int32) and Write(Char[], Int32, Int32) method overloads read and write the number of characters specified by the count parameter. These are to be distinguished from BufferedStream.Read and BufferedStream.Write, which read and write the number of bytes specified by the count parameter. Use the BufferedStream methods only for reading and writing an integral number of byte array elements.

@johnanson
Copy link
Author

johnanson commented May 15, 2019 via email

@martin9700
Copy link
Owner

Nice work. Do you know how contribute your code to the repository?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants