   "Block storage backed by files in nested directories. Each block is stored in
   a separate file.
 
-  In many filesystems, directories are limited to 4,096 entries. In order to
-  avoid this limit (and make navigating the blocks a bit more efficient), block
-  content is stored in nested directories three levels deep. All path elements
-  are lower-case hex-encoded bytes from the multihash.
-
-  The first level is the two-byte multihash prefix, which designates the
-  algorithm and digest length. There will usually only be one or two of these
-  directories. The second and third levels are formed by the first two bytes of
-  the hash digest. Finally, the block is stored in a file containing the rest of
-  the digest.
+  In many filesystems, performance degrades as the number of files in a
+  directory grows. In order to reduce this impact and make navigating the
+  blocks a bit more efficient, block files are stored in directories under the
+  store root. All path elements are lower-case hex-encoded bytes from the
+  multihash.
+
+  The directories under the root consist of the first four bytes of the
+  multihashes of the blocks stored in them. Within each directory, blocks are
+  stored in files whose names consist of the rest of their digests.
 
   Thus, a block containing the content `foobar` would have the sha1 digest
   `97df3501149...` and be stored under the root directory at:
 
-  `root/1114/97/df/35011497df3588b5a3...`
-
-  Using this scheme, leaf directories should start approaching the limit once the
-  user has 2^28 entries, or about 268 million blocks."
+  `root/111497df/35011497df3588b5a3...`
+
+  This implementation tries to match the IPFS fs-repo behavior so that the
+  on-disk representations remain compatible."
   (:require
     (blocks
       [core :as block]


;; ## File Block Functions

(defn- file-stats
  "Calculates storage stats for a block file."
  [^File file]

  (let [hex (multihash/hex id)]
    (io/file
      root
      (subs hex 0 dir-prefix-length)
      (subs hex dir-prefix-length))))


(defn- file->id
