You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
(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".
bearophile_hugs reported this on 2013-02-05T17:04:53Z
Transfered from https://issues.dlang.org/show_bug.cgi?id=9455
Description
The text was updated successfully, but these errors were encountered: