FileBase.copyTo

Copies the rest of this file to the other. The positions of both files are appropriately incremented, as if one called read()/write() to copy the file. The number of copied bytes is returned.

struct FileBase
version(linux)
size_t
copyTo
(,
size_t n = ptrdiff_t.max
)

Examples

Copies the rest of this file to the other. The positions of both files are appropriately incremented, as if one called read()/write() to copy the file. The number of copied bytes is returned.

import std.conv : to;

auto a = tempFile.file;
auto b = tempFile.file;
immutable s = "This will be copied to the other file.";
a.write(s);
a.position = 0;
a.copyTo(b);
assert(a.position == s.length);

b.position = 0;

char[s.length] buf;
assert(b.read(buf) == s.length);
assert(buf == s);

Meta