May 21, 2018 Copying an std.stdio.File into another one | ||||
---|---|---|---|---|
| ||||
What's the correct way to copy a `File` into another one in D?
If `LockingTextReader` wasn't undocumented, I'd have gone for that approach:
> import std.algorithm.mutation : copy;
> import std.stdio : File, LockingTextReader;
>
> void main()
> {
> auto a = File("a.txt", "r");
> auto b = File("b.txt", "w");
>
> a.LockingTextReader.copy(b.lockingTextWriter);
> }
Side-note:
Although the example code suggest otherwise, I'm not talking about copying actual files on disk. In such a case I'd just use `std.file.copy` ;)
So, just imagine `a` were `stdout` of process pipe.
Kind regards,
Elias
|
May 21, 2018 Re: Copying an std.stdio.File into another one | ||||
---|---|---|---|---|
| ||||
Posted in reply to 0xEAB | On 21/05/2018 11:50 PM, 0xEAB wrote:
> What's the correct way to copy a `File` into another one in D?
>
> If `LockingTextReader` wasn't undocumented, I'd have gone for that approach:
>
>> import std.algorithm.mutation : copy;
>> import std.stdio : File, LockingTextReader;
>>
>> void main()
>> {
>> auto a = File("a.txt", "r");
>> auto b = File("b.txt", "w");
>>
>> a.LockingTextReader.copy(b.lockingTextWriter);
>> }
>
>
> Side-note:
> Although the example code suggest otherwise, I'm not talking about copying actual files on disk. In such a case I'd just use `std.file.copy` ;)
> So, just imagine `a` were `stdout` of process pipe.
>
>
> Kind regards,
> Elias
I would probably start by reading it byChunk and writing it out as a rawWrite or something along those lines. That way its using a nice buffer (to limit memory usage).
|
Copyright © 1999-2021 by the D Language Foundation