Code Explainers

Code explainers tagged #filesystem

php
<?php
 
final class RotatingFileLogger
{

How a rotating file logger works in PHP

logging file-rotation io
Intermediate 9 steps
rust
use std::collections::HashSet;
use std::fs;
use std::path::{Path, PathBuf};
use std::thread;

Polling a directory for new files in Rust

polling filesystem callbacks
Intermediate 6 steps
go
package dedup
 
import (
	"crypto/sha256"

Finding duplicate files by content hash in Go

hashing filesystem deduplication
Intermediate 8 steps
go
package storage
 
import (
	"errors"

Preventing path traversal in Go

path-traversal input-validation security
Intermediate 9 steps
python
from pathlib import Path
from typing import Iterator
 
 

Filtering files with pathlib.glob

generators filesystem filtering
Intermediate 6 steps
ruby
require 'set'
 
class DirectoryWatcher
  def initialize(path, pattern: '**/*', interval: 1.0)

Polling for file changes in Ruby

polling filesystem diffing
Intermediate 7 steps
python
import os
import shutil
import tempfile
from contextlib import contextmanager

Transactional file operations in Python

transactions rollback closures
Intermediate 8 steps
php
<?php
 
namespace App\Support;
 

Recursively finding files with SPL iterators in PHP

recursion iterators filesystem
Intermediate 7 steps
python
from pathlib import Path
from collections import defaultdict
 
from PIL import Image

Finding near-duplicate images by perceptual hash

perceptual-hashing clustering hamming-distance
Intermediate 9 steps
go
package fsutil
 
import (
	"io/fs"

Walking a directory tree to find large files in Go

filesystem recursion closures
Intermediate 7 steps
php
<?php
 
namespace App\Cache;
 

A content-hashed fragment cache in PHP

caching content-hashing atomic-writes
Intermediate 10 steps
go
package server
 
import (
	"net/http"

Serving cached static assets in Gin

caching static-files middleware
Intermediate 7 steps
python
import os
import time
from pathlib import Path
 

Polling a directory for file changes in Python

polling filesystem set-operations
Intermediate 8 steps
rust
use std::fs;
use std::io;
use std::path::{Path, PathBuf};
 

Recursive file search by extension in Rust

recursion filesystem error-handling
Intermediate 8 steps
python
from pathlib import Path
 
 
def print_tree(root, prefix="", show_hidden=False):

Printing a directory tree with recursion

recursion filesystem sorting
Intermediate 6 steps
python
import os
import tempfile
from pathlib import Path
from typing import Union

How atomic file writes work in Python

atomicity filesystem durability
Advanced 7 steps