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
Type: string

string repreesenting file path.

up_to
Type: size_t

max buffer size. default value is size_t.max.

Return Value

Type: Promise!(void[])

Promise of untyped array of bytes read

Examples

1 import std.file : write, remove;
2 import dpromise.utils : runEventloop;
3 
4 write("hoge.txt", "hogehogepiyopiyo");
5 scope(exit) remove("hoge.txt");
6 
7 readAsync("hoge.txt").then(
8   (data) {
9     assert(data !is null);
10     assert(cast(string)data == "hogehogepiyopiyo");
11   }
12 );
13 
14 readAsync("hoge.txt", 8).then(
15   (data) {
16     assert(data !is null);
17     assert(cast(string)data == "hogehoge");
18   }
19 );
20 
21 runEventloop();

See Also

Meta