 }
 
 
+// Write a single line of output to stdout.
 func writeln(data: NSData, offset: Int, bytesPerLine: Int) {
 
+    // I've forgotten why this ugly cast was needed.
     let bytes = UnsafePointer<UInt8>(data.bytes)
 
+    // Write the line number.
     print(String(format: "%6X |", offset))
 
     for i in 0 ..< bytesPerLine {
+
+        // Write an extra space in front of every fourth byte except the first.
+        if i > 0 && i % 4 == 0 {
+            print(" ")
+        }
+
+        // Write the byte in hex form, or a spacer if we're out of bytes.
         if i < data.length {
             print(String(format: " %02X", bytes[i]))
         } else {
             print("   ")
         }
-        if ((i + 1) % 4 == 0 && i != bytesPerLine - 1) {
-            print(" ")
-        }
     }
 
     print(" | ")
+
+    // Write a character for each byte in the printable ascii range.
     for i in 0 ..< data.length {
         if bytes[i] >= 32 && bytes[i] <= 126 {
             print(String(format: "%c", bytes[i]))

}


func dump(file: NSFileHandle, var offset: Int, var bytesToRead: Int, bytesPerLine: Int) {

    var data: NSData

    // Attempting to seek into an unseekable stream will throw an exception
    // that we have no way of handling.
    if offset != 0 {
        file.seekToFileOffset(UInt64(offset))
    }

    // Read operations can throw exceptions that we have no way of handling.
    while true {
        if bytesToRead > -1 && bytesToRead < bytesPerLine {
            data = file.readDataOfLength(bytesToRead)

#!/usr/bin/env swift
/*
    Hexdump command line utility.

    This code was written to target Swift 1.1 (November 2014), an early
    and surprisingly immature release of the language. It won't compile
