Inspired by Nikronic’s solution, I made a similar class that reads from Tar archives.
I noticed that it didn’t work out-of-the-box with DataLoaders with multiple workers (depends on the OS/multiprocessing method), so this new class essentially opens a different TarFile (with unique file handles) per worker process.
I also added some methods to access files, including text and images, to allow easier subclassing; and the Tar archive’s content is cached on first read (takes under a minute for a 140GB Tar file with >1M files).
In case you want to check it out: Simple Tar Dataset on GitHub 70.