Mert Özen Further With Every Line

Blog

Mert Özen's blog posts on software development, backend, frontend, and DevOps.

Series
11 posts found #io
I/O and Serialization in .NET 11: Union Serialization, JSON Lines, In-Memory Streams and Zstandard
Backend PART 11

I/O and Serialization in .NET 11: Union Serialization, JSON Lines, In-Memory Streams and Zstandard

In .NET 11, System.Text.Json serializes C# 15 unions without a wrapper and writes JSON Lines with SerializeAsyncEnumerable; System.IO.Compression gained Zstandard, and ZIP gained passwords and CRC32 validation. We show the new in-memory streams, closed hierarchy polymorphism and two behavior changes that can break old tests (an empty GZip is now 20 bytes, a corrupted zip entry now throws), compared with .NET 10.

14 Nov 2026 11 min 2
What Changed in I/O and Serialization from .NET 6 to .NET 10
Backend PART 10

What Changed in I/O and Serialization from .NET 6 to .NET 10

Most of what arrived in I/O and serialization from .NET 6 to .NET 10 are ready-made APIs that replace hand-written loops, naming policies and checks: RandomAccess, ReadExactly, File.ReadLinesAsync, SnakeCaseLower, JsonUnmappedMemberHandling, JsonSerializerOptions.Web and Strict. We collect each version's additions with working before-and-after examples and the places where an upgrade silently changes behavior.

14 Nov 2026 11 min 2
Large Files and Memory-Mapped Files: Processing Gigabytes with Constant Memory
Backend PART 09

Large Files and Memory-Mapped Files: Processing Gigabytes with Constant Memory

Processing a large file with constant memory is not enough, allocation has to go to zero too: on a 5 GB order log, File.ReadLines took 14.5 seconds with 54 MB of memory but 35 GB of allocation, while a rented buffer and a byte parser finished the same job in 2.5 seconds. We split the file into line-aligned offset ranges processed in parallel through a Channel and show with real measurements when memory-mapped files help and how they affect the working set.

14 Nov 2026 13 min 2
Compression and Archives: GZip, Brotli, ZipArchive's Async APIs and Zip Slip
Backend PART 08

Compression and Archives: GZip, Brotli, ZipArchive's Async APIs and Zip Slip

Sending a large zip to a user needs no file or MemoryStream: ZipArchive's Create mode writes entries straight to the response body, but because .NET 10's async ZIP APIs still write the end of each entry synchronously, Kestrel needs an explicit allowance. We measure GZip, ZLib, Deflate and Brotli at each level, compare zip with tar.gz and safely extract an uploaded zip against Zip Slip and zip bombs.

14 Nov 2026 15 min 2
Working with CSV: RFC 4180, Turkish Excel, Encodings and CSV Injection
Backend PART 07

Working with CSV: RFC 4180, Turkish Excel, Encodings and CSV Injection

CSV has to be parsed with a reader that knows RFC 4180's quoting rules, not string.Split, and every number with an explicit culture; on a tr-TR server decimal.Parse("1234.50") silently returns 123450. We import a Windows-1254 bank file with CsvHelper 34 without stopping at bad rows, write an export that opens correctly in Turkish Excel, add CSV injection protection and measure CsvHelper, Sep and Sylvan.

14 Nov 2026 16 min 2
Working with XML: XmlReader, LINQ to XML, XmlSerializer and Secure Defaults
Backend PART 06

Working with XML: XmlReader, LINQ to XML, XmlSerializer and Secure Defaults

Hybrid reading, where XmlReader walks a large XML file and turns each document into a short-lived XElement, combines the convenience of LINQ to XML with constant memory: on a 267 MB file XDocument used a 703 MB heap, the hybrid approach 8.5 MB. With a UBL-like Bookstore invoice we cover namespaces, XSD validation, XmlSerializer versus DataContractSerializer, XmlSerializer's uncached constructors and .NET's defaults against XXE.

14 Nov 2026 14 min 2
System.Text.Json in Depth 2: Source Generation, JsonNode/Utf8JsonReader and Streaming Large JSON
Backend PART 05

System.Text.Json in Depth 2: Source Generation, JsonNode/Utf8JsonReader and Streaming Large JSON

Deserializing a large JSON export into a List<T> pushes the heap past twice the file size; with DeserializeAsyncEnumerable the same job finishes in small, constant memory. We measure this on a 1-million-order Bookstore export and cover the startup and fast-path gains of source generation, its behavior under Native AOT, choosing between JsonDocument, JsonNode and Utf8JsonReader, JsonSchemaExporter and migrating from Newtonsoft.Json.

14 Nov 2026 13 min 2
System.Text.Json in Depth 1: Options, Converters, Polymorphism and Strict Mode
Backend PART 04

System.Text.Json in Depth 1: Options, Converters, Polymorphism and Strict Mode

By default System.Text.Json takes the last value of a duplicate property and silently skips missing and unknown fields; for external payloads you close that with .NET 10's JsonSerializerOptions.Strict and AllowDuplicateProperties = false. We show the web defaults, naming policies, required and nullable rules, polymorphism with Bookstore's PaymentMethod hierarchy, a Money converter and contract customization, all with real output.

14 Nov 2026 13 min 2
System.IO.Pipelines: Copy-Free Parsing with PipeReader, PipeWriter and ReadOnlySequence
Backend PART 03

System.IO.Pipelines: Copy-Free Parsing with PipeReader, PipeWriter and ReadOnlySequence

System.IO.Pipelines takes over the work of lines split across buffers, buffer growth and copying, and lets you parse data without turning it into strings; the key to using it correctly is the AdvanceTo(consumed, examined) rule. We parse Bookstore's NDJSON order stream with PipeReader, hand it to a Channel, and show backpressure and the difference from StreamReader with real BenchmarkDotNet numbers.

14 Nov 2026 12 min 2
FileStream and Async File I/O: FileStreamOptions, RandomAccess and Atomic Writes
Backend PART 02

FileStream and Async File I/O: FileStreamOptions, RandomAccess and Atomic Writes

To replace a file without ever leaving it half-written, write the content to a temporary file in the same folder, push it to disk with Flush(flushToDisk: true) and swap it in with File.Move. We cover FileStreamOptions, async I/O on Windows vs Linux, offset-based reads with RandomAccess, race-free creation with CreateNew and a Worker that catches what FileSystemWatcher misses, using Bookstore examples.

14 Nov 2026 16 min 2
The Stream Model in .NET: Short Reads, Decorator Chains and leaveOpen
Backend PART 01

The Stream Model in .NET: Short Reads, Decorator Chains and leaveOpen

Stream.Read returns the bytes available right now, not the count you asked for, so fixed-size data needs ReadExactly. We write and read Bookstore's order export through a FileStream, GZipStream and CryptoStream chain and show dispose order, leaveOpen, copying with ArrayPool and writing your own Stream, all with real output.

14 Nov 2026 14 min 2
Blog Map