diff --git a/src/std/io/driver/sync.d b/src/std/io/driver/sync.d index 3bd0e61..284a915 100644 --- a/src/std/io/driver/sync.d +++ b/src/std/io/driver/sync.d @@ -143,7 +143,12 @@ shared @safe @nogc: { size_t total; foreach (b; bufs) - total += read(f, b); + { + immutable len = read(f, b); + total += len; + if (len < b.length) + break; + } return total; } } @@ -179,7 +184,12 @@ shared @safe @nogc: { size_t total; foreach (b; bufs) - total += write(f, b); + { + immutable len = write(f, b); + total += len; + if (len < b.length) + break; + } return total; } } diff --git a/src/std/io/file.d b/src/std/io/file.d index 14aa65b..c602962 100644 --- a/src/std/io/file.d +++ b/src/std/io/file.d @@ -255,6 +255,17 @@ struct File assert(f.read(buf[$ / 2 .. $], buf[0 .. $ / 2]) == buf.length); } + @("partial reads") + unittest + { + auto f = File("LICENSE.txt"); + ubyte[256] buf = void; + auto len = f.read(buf[$ / 2 .. $], buf[0 .. $ / 2]); + while (len == buf.length) + len = f.read(buf[$ / 2 .. $], buf[0 .. $ / 2]); + assert(len < buf.length); + } + /** Write buffer content to file.