On 2/1/18 8:27 PM, Seb wrote:
On Thursday, 1 February 2018 at 21:42:33 UTC, Steven Schveighoffer wrote:
On 2/1/18 4:36 PM, Jerry Ferris wrote:
Hello,
I'm developing a program that will either receive data from stdin or
a file, and pass it along to a function for processing. I want to
place this data into a buffer so there only has to be one version of
the function. However, since I'm new to D, I'm unsure how to go about
this in the most idiomatic way.
https://dlang.org/phobos/std_file.html#read
Then cast to ubyte[].
There's also always std.string.representation which imho looks nicer
then the cast:
https://dlang.org/library/std/string/representation.html
std.file.read returns a void[].
I didn't see one that returns a ubyte[], and using the readText version
is going to validate the text I think (which may not be desired). It
really depends on the use case of the OP, but his original code was
working with ubyte[] without validation, so I suggested the void[]
return with cast.
It's a shame, actually, that ubyte[] isn't returned from read. I
remember discussions at some point to change it, but that was shot down
for some reason.
-Steve