2016-10-06 20:06:51 +00:00
|
|
|
/++ dub.sdl:
|
|
|
|
name "test"
|
|
|
|
dependency "vibe-core" path=".."
|
|
|
|
+/
|
|
|
|
module test;
|
|
|
|
|
|
|
|
import vibe.core.file;
|
|
|
|
|
2016-12-19 20:57:52 +00:00
|
|
|
enum ubyte[] bytes(BYTES...) = [BYTES];
|
|
|
|
|
2016-10-06 20:06:51 +00:00
|
|
|
void main()
|
|
|
|
{
|
|
|
|
auto f = openFile("test.dat", FileMode.createTrunc);
|
|
|
|
assert(f.size == 0);
|
2017-02-16 22:37:14 +00:00
|
|
|
assert(f.tell == 0);
|
2016-12-19 20:57:52 +00:00
|
|
|
f.write(bytes!(1, 2, 3, 4, 5));
|
2016-10-06 20:06:51 +00:00
|
|
|
assert(f.size == 5);
|
2017-02-16 22:37:14 +00:00
|
|
|
assert(f.tell == 5);
|
2016-10-06 20:06:51 +00:00
|
|
|
f.seek(0);
|
2017-02-16 22:37:14 +00:00
|
|
|
assert(f.tell == 0);
|
2016-12-19 20:57:52 +00:00
|
|
|
f.write(bytes!(1, 2, 3, 4, 5));
|
2016-10-06 20:06:51 +00:00
|
|
|
assert(f.size == 5);
|
2017-02-16 22:37:14 +00:00
|
|
|
assert(f.tell == 5);
|
2016-12-19 20:57:52 +00:00
|
|
|
f.write(bytes!(6, 7, 8, 9, 10));
|
2016-10-06 20:06:51 +00:00
|
|
|
assert(f.size == 10);
|
2017-02-16 22:37:14 +00:00
|
|
|
assert(f.tell == 10);
|
2016-10-06 20:06:51 +00:00
|
|
|
ubyte[5] dst;
|
|
|
|
f.seek(2);
|
2017-02-16 22:37:14 +00:00
|
|
|
assert(f.tell == 2);
|
2016-10-06 20:06:51 +00:00
|
|
|
f.read(dst);
|
2017-02-16 22:37:14 +00:00
|
|
|
assert(f.tell == 7);
|
2016-12-19 20:57:52 +00:00
|
|
|
assert(dst[] == bytes!(3, 4, 5, 6, 7));
|
2016-10-06 20:15:25 +00:00
|
|
|
f.close();
|
|
|
|
|
|
|
|
removeFile("test.dat");
|
2016-10-06 20:06:51 +00:00
|
|
|
}
|