apple/swift-nio

NIOFileSystem: No API to get the on-disk size

Open

#3,650 opened on Jul 9, 2026

View on GitHub
 (2 comments) (0 reactions) (0 assignees)Swift (749 forks)batch import
good first issuekind/enhancement

Repository metrics

Stars
 (8,453 stars)
PR merge metrics
 (Avg merge 9d 10h) (15 merged PRs in 30d)

Description

NIOFileSystem's FileInfo.size always reports the "apparent size" which is the actual file size (du -Ams report similar stuff) and that's good & correct.

It would be great to also get an .onDiskSize which reports back what's actually used on disk. This is important to account for two things

  1. holes in files
# let's create a 1GB file that's mostly a hole
$ rm -f /tmp/hole && dd if=/dev/urandom bs=1 count=1 seek=$((1024*1024*1024)) of=/tmp/hole
1+0 records in
1+0 records out
1 bytes transferred in 0.000084 secs (11905 bytes/sec)

# apparent size is 1GB, fine
$ du -Ah /tmp/hole
1.0G	/tmp/hole

# but it only occupies 4 kB on disk
$ du -h /tmp/hole
4.0K	/tmp/hole
  1. APFS compressed files

The implementation is just S_BLKSIZE * st_blocks where st_blocks is from stat. And please note it is S_BLKSIZE (it's 512, I think required by posix) and NOT stat.st_blksize (which can be 4kB or 1MB, depending on the fs), that's the preferred I/O size or something and must be ignored.

Contributor guide