Code Explainers

Code explainers tagged #file-io

rust
use std::fs;
use std::path::Path;
 
use regex::Regex;

Redacting emails in a file with Rust

regex file-io closures
Intermediate 6 steps
rust
use std::fs::{File, OpenOptions};
use std::io::{self, Write};
use std::path::Path;
 

A buffered log writer in Rust

buffering raii file-io
Intermediate 9 steps
java
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.http.HttpClient;

Streaming a file download with Java's HttpClient

http-client streaming file-io
Intermediate 6 steps
python
import csv
from pathlib import Path
 
 

Splitting a large CSV into smaller files

file-io streaming csv
Intermediate 8 steps
python
import hashlib
from pathlib import Path
 
 

Streaming SHA-256 checksums in Python

hashing file-io streaming
Intermediate 6 steps
rust
use std::fs::File;
use std::io::{self, BufWriter};
use std::path::Path;
 

Serializing config to JSON in Rust

serialization serde file-io
Intermediate 7 steps
java
package com.example.fs;
 
import java.io.IOException;
import java.nio.file.FileSystems;

Watching a directory with Java NIO

file-io event-loop resource-management
Intermediate 8 steps
java
public List<Employee> parseEmployees(Path csvPath) throws IOException {
    List<Employee> employees = new ArrayList<>();
 
    try (BufferedReader reader = Files.newBufferedReader(csvPath, StandardCharsets.UTF_8)) {

Parsing a CSV into typed objects in Java

csv-parsing file-io try-with-resources
Intermediate 7 steps
java
package com.example.logs;
 
import java.io.IOException;
import java.io.UncheckedIOException;

Counting HTTP statuses with Java streams

streams regex file-io
Intermediate 6 steps
php
<?php
 
declare(strict_types=1);
 

Streaming file lines with a PHP generator

generators lazy-evaluation file-io
Intermediate 7 steps
python
import gzip
from pathlib import Path
from typing import Iterator
 

Streaming TSV records with Python generators

generators lazy-evaluation file-io
Intermediate 5 steps
go
package main
 
import (
	"bufio"

Counting matching lines in Go with bufio

file-io buffered-scanning error-handling
Intermediate 4 steps