readAsync

Read file path with asynchronous IO and returns data read as a promise of untyped array. If file size is larger than up_to, only up_to bytes read.

If an error occurred, the promise will be rejected.

nothrow
Promise!(void[])
readAsync
(
string path
,
size_t up_to = size_t.max
)

Parameters

path string

string repreesenting file path.

up_to size_t

max buffer size. default value is size_t.max.

Return Value

Type: Promise!(void[])

Promise of untyped array of bytes read

Examples

import std.file : write, remove;
import dpromise.utils : runEventloop;

write("hoge.txt", "hogehogepiyopiyo");
scope(exit) remove("hoge.txt");

readAsync("hoge.txt").then(
  (data) {
    assert(data !is null);
    assert(cast(string)data == "hogehogepiyopiyo");
  }
);

readAsync("hoge.txt", 8).then(
  (data) {
    assert(data !is null);
    assert(cast(string)data == "hogehoge");
  }
);

runEventloop();

See Also

Meta