Files
d/source/zap/MemoryMapped.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

43 lines
658 B
D

module zap.MemoryMapped;
import std.mmfile : MmFile;
import java.nio.ByteBuffer;
import java.nio.channels.ReadableByteChannel;
final class MemoryMapped : ReadableByteChannel
{
public: //Methods.
this(MmFile file)
{
this.file = file;
}
bool isOpen()
{
return true;
}
void close()
{
}
///Setup map from file to dst.
size_t read(ref ByteBuffer dst)
{
import std.algorithm : min;
auto size = min(dst.remaining(), file.length - index);
if(size == 0)
return 0;
dst.buffer = cast(ubyte[])file[index..index+size];
dst.position += size;
index += size;
return size;
}
private: //Variables.
MmFile file;
size_t index;
}