Skip to main content

File

⚠️ This page was initialized by AI translation and may contain outdated or inaccurate information. If there are inaccuracies, please submit changes to correct these errors Correct

Access components​

\Co\IO::File() : File;

###API

public function getContents(string $path): Promise;
public function open(string $path, string $mode): Stream;

Overview​

ripple provides asynchronous operation methods for files, allowing developers to read file contents and operate file streams through streams that do not block the process.

Instructions​

You can read the file in the following way

\Co\IO::File()->getContents(__FILE__)->then(function(string $value){

});
\Co\async(function(){
$value = \Co\await(
\Co\IO::File()->getContents(__FILE__)
);
});

You can also open a file stream in the following way

$stream = \Co\IO::File()->open('file.txt','r');

Stream follows the StreamInterface development of PSR specifications. For Stream operations, please see the Stream operation section.