Code Snippets

Tag: Io

Write Lines to a File

Open a file for writing and emit a few lines.

Author: chris

Read a File Line by Line

Iterate a text file lazily with a context manager.

Author: chris

Write to a File in PHP

Use file_put_contents with LOCK_EX for an atomic write.

Author: chris

Read a File Line by Line in PHP

Use SplFileObject to iterate a file lazily without loading it all into RAM.

Author: chris

Write a File in Go

Atomically write bytes to disk with os.WriteFile.

Author: chris

Read a File to String in Go

Read an entire file into memory with os.ReadFile.

Author: chris

Write a File in Rust

Persist a string atomically using std::fs::write.

Author: chris

Read a File to String in Rust

Read an entire file into a String using std::fs::read_to_string.

Author: chris