@ai-ecoverse/slicc-kernel 1.147.7 → 1.147.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2963,7 +2963,7 @@ var KERNEL_VERSION, OS_RELEASE;
2963
2963
  var init_version = __esm({
2964
2964
  "src/version.ts"() {
2965
2965
  "use strict";
2966
- KERNEL_VERSION = true ? "1.147.7" : "0.0.0-dev";
2966
+ KERNEL_VERSION = true ? "1.147.8" : "0.0.0-dev";
2967
2967
  OS_RELEASE = "6.0.0-slicc";
2968
2968
  }
2969
2969
  });
@@ -8088,6 +8088,12 @@ var init_js_kernel = __esm({
8088
8088
  });
8089
8089
 
8090
8090
  // src/process/js/js-io.ts
8091
+ function intoTarget(into, offset, length) {
8092
+ if (!into) return void 0;
8093
+ if (!Number.isSafeInteger(offset) || offset < 0 || offset + length > into.length)
8094
+ throw Object.assign(new RangeError("read: the buffer is too small"), { code: "EINVAL" });
8095
+ return { into, at: offset };
8096
+ }
8091
8097
  function typeOf(info) {
8092
8098
  if (info.meta && "dir" in info.meta) return "directory";
8093
8099
  if (info.meta && "device" in info.meta) return "device";
@@ -8173,7 +8179,7 @@ function openRequest(abs, o) {
8173
8179
  function index2(n, what) {
8174
8180
  if (!Number.isSafeInteger(n) || n < 0) throw new JsCallError("EINVAL", what);
8175
8181
  }
8176
- var CHUNK, MAX_IO, O_WRONLY4, O_RDWR4, O_APPEND2, BLOCK, O_NONBLOCK_OPEN;
8182
+ var CHUNK, MAX_IO, MAX_PREAD, O_WRONLY4, O_RDWR4, O_APPEND2, BLOCK, O_NONBLOCK_OPEN;
8177
8183
  var init_js_io = __esm({
8178
8184
  "src/process/js/js-io.ts"() {
8179
8185
  "use strict";
@@ -8181,6 +8187,7 @@ var init_js_io = __esm({
8181
8187
  init_js_kernel();
8182
8188
  CHUNK = 64 * 1024;
8183
8189
  MAX_IO = 1024 * 1024;
8190
+ MAX_PREAD = 16 * 1024 * 1024;
8184
8191
  O_WRONLY4 = 1;
8185
8192
  O_RDWR4 = 2;
8186
8193
  O_APPEND2 = 1024;
@@ -17221,6 +17228,23 @@ function syncFile(kernel, fd, path, append, forget) {
17221
17228
  const live = () => {
17222
17229
  if (!open) throw new JsCallError("EBADF", path);
17223
17230
  };
17231
+ const pread = (position, length, target) => {
17232
+ index2(position, "read");
17233
+ index2(length, "read");
17234
+ const parts = [];
17235
+ let got = 0;
17236
+ do {
17237
+ live();
17238
+ const max = Math.min(length - got, MAX_PREAD);
17239
+ if (max <= 0) break;
17240
+ const chunk = kernel.bytes({ op: "fd-pread", fd, offset: position + got, max });
17241
+ if (chunk.length === 0) break;
17242
+ if (target) target.into.set(chunk, target.at + got);
17243
+ else parts.push(chunk);
17244
+ got += chunk.length;
17245
+ } while (got < length);
17246
+ return target ? got : joined(parts, got);
17247
+ };
17224
17248
  const file = {
17225
17249
  fd,
17226
17250
  path,
@@ -17228,21 +17252,11 @@ function syncFile(kernel, fd, path, append, forget) {
17228
17252
  live();
17229
17253
  return kernel.json({ op: "fd-vfs-stat", fd }).size;
17230
17254
  },
17255
+ readInto(position, into, offset = 0, length = into.length - offset) {
17256
+ return pread(position, length, intoTarget(into, offset, length));
17257
+ },
17231
17258
  read(position, length) {
17232
- index2(position, "read");
17233
- index2(length, "read");
17234
- const parts = [];
17235
- let got = 0;
17236
- do {
17237
- live();
17238
- const max = Math.min(length - got, MAX_IO);
17239
- if (max <= 0) break;
17240
- const chunk = kernel.bytes({ op: "fd-pread", fd, offset: position + got, max });
17241
- if (chunk.length === 0) break;
17242
- parts.push(chunk);
17243
- got += chunk.length;
17244
- } while (got < length);
17245
- return joined(parts, got);
17259
+ return pread(position, length);
17246
17260
  },
17247
17261
  write(position, data) {
17248
17262
  index2(position, "write");
@@ -18496,6 +18510,23 @@ function fileHandle(kernel, fd, path, append, forget) {
18496
18510
  const live = () => {
18497
18511
  if (!open) throw new JsCallError("EBADF", path);
18498
18512
  };
18513
+ const pread = async (position, length, target) => {
18514
+ index2(position, "read");
18515
+ index2(length, "read");
18516
+ const parts = [];
18517
+ let got = 0;
18518
+ do {
18519
+ live();
18520
+ const max = Math.min(length - got, MAX_PREAD);
18521
+ if (max <= 0) break;
18522
+ const chunk = await kernel.bytes({ op: "fd-pread", fd, offset: position + got, max });
18523
+ if (chunk.length === 0) break;
18524
+ if (target) target.into.set(chunk, target.at + got);
18525
+ else parts.push(chunk);
18526
+ got += chunk.length;
18527
+ } while (got < length);
18528
+ return target ? got : joined(parts, got);
18529
+ };
18499
18530
  const file = {
18500
18531
  fd,
18501
18532
  path,
@@ -18504,21 +18535,11 @@ function fileHandle(kernel, fd, path, append, forget) {
18504
18535
  const s = await kernel.json({ op: "fd-vfs-stat", fd });
18505
18536
  return s.size;
18506
18537
  },
18538
+ async readInto(position, into, offset = 0, length = into.length - offset) {
18539
+ return await pread(position, length, intoTarget(into, offset, length));
18540
+ },
18507
18541
  async read(position, length) {
18508
- index2(position, "read");
18509
- index2(length, "read");
18510
- const parts = [];
18511
- let got = 0;
18512
- do {
18513
- live();
18514
- const max = Math.min(length - got, MAX_IO);
18515
- if (max <= 0) break;
18516
- const chunk = await kernel.bytes({ op: "fd-pread", fd, offset: position + got, max });
18517
- if (chunk.length === 0) break;
18518
- parts.push(chunk);
18519
- got += chunk.length;
18520
- } while (got < length);
18521
- return joined(parts, got);
18542
+ return await pread(position, length);
18522
18543
  },
18523
18544
  async write(position, data) {
18524
18545
  index2(position, "write");