The following example
const file = await Deno.open("file.txt", { create: true, write: true });
file.seek(BigInt(0), 0);
Results in the following error
error: Uncaught TypeError: Do not know how to serialize a BigInt
at JSON.stringify (<anonymous>)
at encode ($deno$/ops/dispatch_json.ts:37:18)
at Object.sendAsync ($deno$/ops/dispatch_json.ts:86:19)
at Object.seek ($deno$/ops/fs/seek.ts:18:10)
at File.seek ($deno$/files.ts:87:12)
at file:///Users/caspervonb/seek_bigint.js:2:6
TypeScript does technically disallow it but the offset is u64 in the underlying implementation so we shouldn't toss away 32 bits of indexing space.
Somewhat of a dupe https://github.com/denoland/deno/issues/2079
Agree we should make this work
So what's the preferred way forward here; allow transparent serialization of bigint into u64/i64 or special casing the few ops that use bigints to explicitly deal with hi and lo bits?
This is going to be real hard, we would have to serialize something in another buffer to hold the value of the bigint. I don't think universially implementing some sort of custom JSON serialize/deserialize in JavaScript and Rust would make a huge amount of sense (and would be abysmal performance), so the easiest thing is to just put the value in another buffer and add some sort of flag to the op that it needs to look in the other buffer for actual value.
Rather unusual to require u64 so it's plan to implement this as a minimal op in io.rs. Kinda waiting for whatever is going to happen to the resource table to land before starting on it tho.
Most helpful comment
Agree we should make this work