That is possible, I just used this implementation for a large tar file on a single machine. It may not work in few different situations.
But still the best case even for large datasets is to extract entire dataset and loop over it. Here is the original post that lead to this code:

  
    
    
    Fastest way to read images from uncompressed TAR file in __getitem__ method of Custom Dataset vision
  
  
    Hello everyone 
I have a huge dataset (2 million) of jpg images in one uncompressed TAR file. I also have a txt file each line is the name of the image in TAR file in order. 
img_0000001.jpg
img_0000002.jpg
img_0000003.jpg
...

and images in tar file are exactly the same. 
I searched alot and find out tarfile module is the best one, but when I tried to read images from tar file using name, it takes too long. And the reason is, everytime I call getmemeber(name) method, it calls getmembers() metho…