mirror of
https://github.com/zap-proto/d.git
synced 2026-10-30 15:05:27 +00:00
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.
43 lines
658 B
D
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;
|
|
}
|