File.put()

Bastiaan Veelo Bastiaan at Veelo.net
Fri Jun 8 18:50:56 UTC 2018


Writing a single value to binary file can be done in (at least) 
two ways. Let `f` be a `File`:

```
f.rawWrite((&value)[0 .. 1]);
```

or

```
f.lockingBinaryWriter.put(value);
```

The former way is little talked about, the latter is not even 
documented. As far as I can see, the latter resolves to the 
former [1] if we disregard locking, mode switching and keeping a 
reference count (on Windows).

Shouldn't there be a `File.put()` method for the case where you 
already know that the file is locked and in the right mode? The 
trick to convert a single value to a range so it can be feeded to 
`rawWrite` may not be obvious to everyone.

Or have I just overlooked the obvious way for writing single 
values?

[1] 
https://github.com/dlang/phobos/blob/v2.080.1/std/stdio.d#L3102



More information about the Digitalmars-d-learn mailing list