Beispiel #1
0
std::vector<unsigned char> read(void *pf, Number offset, Number count)
{
    MemoryFile *f = check_file(pf);
    uint64_t o = number_to_uint64(offset);
    if (o >= f->len) {
        return std::vector<unsigned char>();
    }
    uint64_t c = number_to_uint64(count);
    if (o + c > f->len) {
        c = f->len - o;
    }
    return std::vector<unsigned char>(f->view + o, f->view + o + c);
}
Beispiel #2
0
std::vector<unsigned char> readBytes(void *pf, Number count)
{
    FILE *f = check_file(pf);
    uint64_t ncount = number_to_uint64(count);
    std::vector<unsigned char> r(ncount);
    size_t n = fread(const_cast<unsigned char *>(r.data()), 1, ncount, f);
    r.resize(n);
    return r;
}
Beispiel #3
0
void write(void *pf, Number offset, const std::vector<unsigned char> &data)
{
    MemoryFile *f = check_file(pf);
    uint64_t o = number_to_uint64(offset);
    if (o >= f->len) {
        throw RtlException(global::Exception_ValueRangeException, utf8string(""));
    }
    if (o + data.size() > f->len) {
        throw RtlException(global::Exception_ValueRangeException, utf8string(""));
    }
    memcpy(f->view + o, data.data(), data.size());
}