ext-uv/tests/300-fs.phpt

42 lines
1.0 KiB
Plaintext
Raw Normal View History

--TEST--
Check for fs read and close
--FILE--
<?php
define("FIXTURE_PATH", dirname(__FILE__) . "/fixtures/hello.data");
2015-01-18 02:58:40 +01:00
uv_fs_open(uv_default_loop(), FIXTURE_PATH, UV::O_RDONLY, 0, function($r) {
uv_fs_read(uv_default_loop(), $r, $offset = 0, $len = 32, function($stream, $nread, $data) {
2014-11-23 19:02:03 +01:00
if ($nread <= 0) {
if ($nread < 0) {
throw new Exception("read error");
}
2015-01-18 02:58:40 +01:00
uv_fs_close(uv_default_loop(), $stream, function() { });
2014-11-23 19:02:03 +01:00
} else {
2015-01-18 17:24:13 +01:00
echo trim($data) . "\n";
2014-11-23 19:02:03 +01:00
}
});
});
// test offset
2015-01-18 02:58:40 +01:00
uv_fs_open(uv_default_loop(), FIXTURE_PATH, UV::O_RDONLY, 0, function($r) {
uv_fs_read(uv_default_loop(), $r, $offset = 1, $len = 32, function($stream, $nread, $data) {
if ($nread <= 0) {
if ($nread < 0) {
throw new Exception("read error");
}
2015-01-18 02:58:40 +01:00
uv_fs_close(uv_default_loop(), $stream, function() { });
} else {
2015-01-18 17:24:13 +01:00
echo "H" . trim($data) . "\n";
}
});
});
2014-11-23 19:02:03 +01:00
uv_run();
2015-01-18 17:24:13 +01:00
?>
--EXPECT--
2014-11-23 19:02:03 +01:00
Hello
2015-01-18 17:24:13 +01:00
Hello