__zigar‐>describe(stream, is_dir = false) ᴾᴴᴾ - chung-leong/zigar GitHub Wiki
JavaScript | PHP
Obtain a virtual file descriptor for the stream.
Usage:
const std = @import("std");
pub fn save(path: []const u8, text: []const u8) !void {
var file = try std.fs.openFileAbsolute(path, .{});
defer file.close();
_ = try file.write(text);
}
<?php
$m = zigar_use(__DIR__ . "/describe-example-1.zig");
$strm = fopen("php://memory", "w+");
$fd = $m->__zigar->describe($strm);
$m->save("/php://fd/$fd", "Hello multiverse!");
$data = stream_get_contents($strm, null, 0);
debug_zval_dump($data);
string(17) "Hello multiverse!" refcount(2)
Note:
Virtual file descriptors are only usable by the imported Zig module. They are not visible to PHP.
In the example above, file_get_contents("php://fd/$fd") would fail.