Files
d/source/zap/FileDescriptor.d
zeekay fe49a3b74f rebrand Cap'n Proto D port to ZAP
Rename the capnproto-dlang fork to zap-dlang: source/capnproto/ -> source/zap/
(module/import paths capnproto.* -> zap.*), compiler plugin capnpc-dlang ->
zapc-dlang, schemas .capnp -> .zap, Makefile pkg-config/-lcapnp -> zap/-lzap,
README/CONTRIBUTORS rebranded with canonical zap-proto.io/zap-proto.dev/
github.com/zap-proto/d links. Pure mechanical rename: no logic changes.
Upstream Sandstorm MIT headers preserved.
2026-06-19 23:47:11 -07:00

49 lines
843 B
D

module zap.FileDescriptor;
import std.stdio : File;
import java.nio.ByteBuffer;
import java.nio.channels.ReadableByteChannel;
import java.nio.channels.WritableByteChannel;
final class FileDescriptor : ReadableByteChannel, WritableByteChannel
{
public: //Methods.
this(File file)
{
this.file = file;
}
bool isOpen()
{
return true;
}
void close()
{
file.close();
}
///Reads from fd to dst.
size_t read(ref ByteBuffer dst)
{
if(dst.buffer is null)
dst.buffer = new ubyte[](dst.remaining);
file.rawRead(dst.buffer);
dst.position = dst.buffer.length;
dst.limit = dst.buffer.length;
return dst.buffer.length;
}
///Writes from src to fd.
size_t write(ref ByteBuffer src)
{
file.rawWrite(src.buffer[0..src.limit]);
src.position = src.limit;
return src.limit;
}
private: //Variables.
File file;
}