Skip to content

Executable from JSON #979

Answered by guest271314
guest271314 asked this question in Q&A
Discussion options

You must be logged in to vote

I figured it out. Write a plain JavaScript object, using smaller data chunks, to avoid invalid JSON in some writes ending in ,

function main() {
  const err = { errno: 0 };
  const file = std.open("qjs", "w", err);
  let writes = 0;
  let totalBytesWritten = 0;
  while (true) {
    const message = getMessage();
    const str = String.fromCodePoint(...message);
    const { value, done } = JSON.parse(str);
    if (done) {
      file.close();
      sendMessage(
        new Uint8Array(
          [...JSON.stringify({ done, value, totalBytesWritten })].map((s) =>
            s.codePointAt()
          ),
        ),
      );
    } else {
      const u8 = new Uint8Array([...value]);
      totalByt…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by saghul
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant