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); }
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; }
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()); }