Name
SPVM::Go::OS::File - File, TCP, and Pipe Descriptor Wrapper
Description
Go::OS::File class in SPVM represents an operating system file descriptor, TCP socket, or pipe endpoint, similar to os.File in the Go programming language.
Usage
use Go;
use Go::OS::File;
my $file = Go::OS::File->new_pipe_end($fd);
$file->write(Go->bg, "hello");
$file->close;
Details
Go::OS::File wraps file descriptors and libuv stream handles for standard I/O streams ($STDIN, $STDOUT, $STDERR), existing file descriptors, TCP sockets, and pipe endpoints used with Go::OS::Exec::Cmd and non-blocking I/O.
Class Variables
STDIN
our $STDIN : ro Go::OS::File;
Standard input file wrapping file descriptor 0 with no_close enabled.
STDOUT
our $STDOUT : ro Go::OS::File;
Standard output file wrapping file descriptor 1 with no_close enabled.
STDERR
our $STDERR : ro Go::OS::File;
Standard error file wrapping file descriptor 2 with no_close enabled.
Fields
type
has type : ro int;
The internal descriptor type.
fd
has fd : ro int;
The operating system file descriptor.
uv_stream
has uv_stream : UV::Handle::Stream;
The libuv stream handle associated with the TCP socket or pipe endpoint.
finish_cb
has finish_cb : Callback;
The callback invoked to complete or cancel an in-progress read or write operation.
no_close
has no_close : byte;
If true, close throws an exception and DESTROY does not close the descriptor.
closed
has closed : ro byte;
Indicates whether the file has been closed.
Class Methods
new_file
static method new_file : Go::OS::File ($fd : int);
Creates a Go::OS::File object for a non-negative file descriptor $fd with no_close set to 1.
new_tcp
static method new_tcp : Go::OS::File ($fd : int);
Duplicates a non-negative TCP socket file descriptor $fd, initializes a UV::Handle::TCP handle on the event loop, opens the duplicated descriptor, and returns a Go::OS::File object.
new_pipe_end
static method new_pipe_end : Go::OS::File ($fd : int);
Duplicates a non-negative pipe file descriptor $fd, initializes a UV::Handle::Pipe handle on the event loop, opens the duplicated descriptor, and returns a pipe-end Go::OS::File object.
prepare_pipe_end
static method prepare_pipe_end : Go::OS::File ();
Creates a placeholder Go::OS::File object for a pipe endpoint before a file descriptor is attached.
Instance Methods
read
method read : int ($context : Go::Context, $string : mutable string, $length : int = -1, $offset : int = 0);
Reads bytes from the TCP or pipe stream into $string cooperatively with the goroutine scheduler and context $context.
write
method write : int ($context : Go::Context, $string : string, $length : int = -1, $offset : int = 0);
Writes bytes from $string to the TCP or pipe stream cooperatively with the goroutine scheduler and context $context.
close
method close : void ();
Cancels any active operation, closes the libuv stream handle if present, and marks the file as closed unless no_close is set.
DESTROY
method DESTROY : void ();
Calls close automatically when destroyed unless no_close is set.
Well Known Child Classes
See Also
Repository
Author
Yuki Kimoto kimoto.yuki@gmail.com
Copyright & License
Copyright (c) 2026 Yuki Kimoto
MIT License