-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
[API Proposal]: Expose SafeFileHandle.CanSeek #58370
Comments
Tagging subscribers to this area: @dotnet/area-system-io Issue DetailsBackground and motivationRecently, we have introduced new As of today, all these methods support only seekable files. In contrary to API Proposalnamespace Microsoft.Win32.SafeHandles
{
partial class SafeFileHandle
{
public bool CanSeek { get; }
}
} API Usageusing SafeFileHandle fileHandle = File.OpenHandle(path, FileMode.Open, FileAccess.Read);
long fileLength = fileHandle.CanSeek ? RandomAccess.GetLength(fileHandle) : -1; RisksNone. The API has been already implemented for both Windows and Unix and it's being used by
|
Assuming in .NET 7 we remove this constraint, and RandomAccess' methods can be used with any SafeFileHandle regardless of whether it's seekable or not (and if not then the offset will just be ignored), is there still utility for exposing this property as well in .NET 7? |
I think that we are going to remove the constraint for all Also, there might be some value in terms of validating that given path specified by the user does not point to a regular file. |
@adamsitnik We took a quick look today. We think it's OK, but it would be good to get your take on our questions/feedback.
namespace Microsoft.Win32.SafeHandles
{
partial class SafeFileHandle
{
public bool CanSeek { get; }
}
} |
Through #59754, we learned that #58381 will relax I think this means the rationale for this API is no longer valid, and that it shouldn't be added. |
Background and motivation
Recently, we have introduced new
RandomAccess
type (#24847) which exposes some convenient methods for File IO. To use any of these methods, users need to provide aSafeFileHandle
instance which can be obtained by usingFile.OpenHandle
(also a new method introduced in .NET 6).As of today, all these methods support only seekable files. In contrary to
FileStream
,SafeFileHandle
does not exposeCanSeek
property, so the users can't easily check whether they can use the newRandomAccess
type methods.API Proposal
API Usage
Risks
None. The API has been already implemented for both Windows and Unix and it's being used by
FileStream
, but it's internal.The text was updated successfully, but these errors were encountered: