0% found this document useful (0 votes)
14 views2 pages

Scribidi F y

In Episode 5, Gerald demonstrates file handling in WebAssembly by opening a file in read, write, and append modes sequentially. He successfully reads from, overwrites, and appends to a text file, verifying the output matches expectations. Gerald plans to implement persistent storage for future logging sessions.

Uploaded by

horus.philostone
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views2 pages

Scribidi F y

In Episode 5, Gerald demonstrates file handling in WebAssembly by opening a file in read, write, and append modes sequentially. He successfully reads from, overwrites, and appends to a text file, verifying the output matches expectations. Gerald plans to implement persistent storage for future logging sessions.

Uploaded by

horus.philostone
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Here it is.

---

Episode 5: The Three Modes


(Where WebAssembly reads, writes, and appends — in that order)

Tuesday morning. 8:59 AM. Gerald’s keyboard was already warm. He never left.

Today’s goal: open a file three times — once in "r" mode, once in "w" mode, and
once in "a" mode. He called it "full interaction."

He opened a new source file:


triple_access.c

He typed, slowly but with steady purpose:

#include <stdio.h>

int main() {
// Read existing content
FILE *fr = fopen("/sequence.txt", "r");
if (fr != NULL) {
char buffer[64];
while (fgets(buffer, sizeof(buffer), fr)) {
printf("%s", buffer);
}
fclose(fr);
}

// Overwrite the file


FILE *fw = fopen("/sequence.txt", "w");
if (fw == NULL) return 1;
fprintf(fw, "This file has been rewritten.\n");
fclose(fw);

// Append a line
FILE *fa = fopen("/sequence.txt", "a");
if (fa == NULL) return 2;
fprintf(fa, "Then appended by WebAssembly.\n");
fclose(fa);

return 0;
}

He compiled it, without ceremony.

emcc triple_access.c -o triple.html --preload-file sequence.txt

The console remained quiet during compilation. He appreciated that.

He loaded the HTML. The console displayed:

Initial placeholder line.

Then:

This file has been rewritten.


Then appended by WebAssembly.

It had overwritten the file, and then appended. He downloaded it. It matched
exactly.

He added to log.txt:

June 17, 9:22 AM


Tested sequential file modes: read → write → append.
Observed expected file mutation.
Output verified.

He tapped the keyboard lightly.

Then he created a flowchart in ASCII on paper:

[R] → [W] → [A]


↓ ↓ ↓
Read Overwrite Append

He labeled it: "The Life Cycle of a Text File."

At 9:35 AM, Gerald updated plan.txt:

Plan for Wednesday:


Mount IDBFS for persistent txt storage.
Simulate long-term logging session.

He leaned back. Outside, a bird landed on the windowsill. Gerald did not notice.

He was already thinking about persistence.

---

Next up: Episode 6: “The Memory That Lasted” — persistent file storage with
WebAssembly. Ready when you are.

You might also like