2017-02-16 23:49:40 +00:00
|
|
|
/+ dub.sdl:
|
2016-10-06 20:06:51 +00:00
|
|
|
name "test"
|
|
|
|
dependency "vibe-core" path=".."
|
|
|
|
+/
|
|
|
|
module test;
|
|
|
|
|
|
|
|
import vibe.core.file;
|
2019-08-25 12:09:59 +00:00
|
|
|
import std.exception;
|
2016-10-06 20:06:51 +00:00
|
|
|
|
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();
|
|
|
|
|
2019-08-25 12:09:59 +00:00
|
|
|
auto fi = getFileInfo("test.dat");
|
|
|
|
assert(fi.name == "test.dat");
|
|
|
|
assert(fi.isFile);
|
|
|
|
assert(!fi.isDirectory);
|
|
|
|
assert(!fi.isSymlink);
|
|
|
|
assert(!fi.hidden);
|
|
|
|
assert(fi.size == 10);
|
|
|
|
|
|
|
|
assertThrown(getFileInfo("*impossible:file?"));
|
|
|
|
|
2016-10-06 20:15:25 +00:00
|
|
|
removeFile("test.dat");
|
2016-10-06 20:06:51 +00:00
|
|
|
}
|