__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");
var threaded_io = std.Io.Threaded.init_single_threaded;

const io = threaded_io.io();

pub fn save(path: []const u8, text: []const u8) !void {
    var file = try std.Io.Dir.openFileAbsolute(io, path, .{});
    defer file.close(io);
    _ = try file.writeStreaming(io, "", &[1][]const u8{text}, 1);
}
<?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.


Virtual file system