Issue 9455 - File.isBinaryMode and more
Summary: File.isBinaryMode and more
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P4 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-02-05 17:04 UTC by bearophile_hugs
Modified: 2024-12-01 16:16 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2013-02-05 17:04:53 UTC
Some functions I write take a File reference and write some binary data on it. So in their pre-condition I'd like to assert the File to be not just open, but also opened in binary mode. I think currently there is no handy way to know if a std.stdio.File is opened in binary or text mode (or in write or read mode).

After a short discussion on IRC #D with jA_cOp, I think a way to implement this feature is:
- Add isBinaryMode/isWriteable/isReadable properties to File, and implement them as light wrappers around platform-specific functions that get that information.
- in most cases a std.stdio.File is created with a file name and a mode string, while the usage of std.stdio.File.wrapFile() is uncommon. So on systems where those platform-specific functions are not available a workaround is to keep this mode string given to the File.__ctor.
Comment 1 Kevin L 2013-07-09 11:38:23 UTC
(In reply to comment #0)
> - Add isBinaryMode/isWriteable/isReadable properties to File, and implement
> them as light wrappers around platform-specific functions that get that
> information.

I vote that there be five new functions:

* isReadable(inout(C)[] path) (or perhaps canRead()): for files, a std.stdio.open(..., "r") will succeed; for directories, std.file.dirEntries() will succeed.

* isWriteable(inout(C)[] path) (or perhaps canWrite()):  for files, a std.stdio.open(..., "w") will succeed; for directories, creating a new file in the directory will succeed (excluding things like no space on device).  Open question if this function should detect write-only media and return false if so.

* isExecutable(inout(C)[] path) (or perhaps canExecute()): for files, exec()/fork()/popen()/etc. (and wrappers) will succeed; always false for directories.

* isTraversable(inout(C)[] path): always false for files; for directories, a chdir() will succeed OR a file in the directory can be stat()d.  (This is the traditional POSIX view of execute bit on a directory.)

* std.stdio.File.isBinary(): returns true if the file was opened with "rb" or "wb".
Comment 2 dlangBugzillaToGithub 2024-12-01 16:16:18 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/phobos/issues/9597

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB