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.