class_docstr: Reads `Webdataset` data format, and creates index file
  that enables random access.
  
  Example usage:
  ----------
  >> with IndexCreator('data/test.tar','data/test.idx') as ic:
  >>     ic.create_index()
  >> !ls data/
  test.tar  test.idx
  
  Parameters
  ----------
  uri : str
      Path to the archive file.
  idx_path : str
      Path to the index file, that will be created/overwritten.
class_docstr_tok: ["Reads","`","Webdataset","`","data","format",",","and","creates","index","file","that","enables","random","access",".","Example","usage",":","--","--","--","--","--",">",">","with","IndexCreator","(","'data\/test.tar","'",",","'data\/test.idx","'",")","as","ic",":",">",">","ic.create_index","(",")",">",">","!","ls","data\/","test.tar","test.idx","Parameters","--","--","--","--","--","uri",":","str","Path","to","the","archive","file",".","idx_path",":","str","Path","to","the","index","file",",","that","will","be","created\/overwritten","."]
docstr: Retreives the data about the offset, name and size of each component
  using the gnu tar utility, while also filtering out non-file entries
docstr_tok: ["Retreives","the","data","about","the","offset",",","name","and","size","of","each","component","using","the","gnu","tar","utility",",","while","also","filtering","out","non-file","entries"]
code: def _get_data_tar(self):
      """Retreives the data about the offset, name and size of each component
      using the gnu tar utility, while also filtering out non-file entries
      """
  
      tar_blocks_proc = subprocess.Popen(
          ["tar", "--list", "--block-num", "--file", self.uri],
          stdout=subprocess.PIPE,
          stderr=subprocess.PIPE,
      )
      tar_types_sizes_proc = subprocess.Popen(
          ["tar", "--verbose", "--list", "--file", self.uri],
          stdout=subprocess.PIPE,
          stderr=subprocess.PIPE,
      )
  
      tar_blocks = tar_blocks_proc.communicate()[0].split(
          b"\n"
      )  # block <n>: <filepath>
      tar_types_sizes = tar_types_sizes_proc.communicate()[0].split(
          b"\n"
      )  # <type>... <size> <date> <name>
  
      # Extracting
      for blocks_line, types_sizes_line in zip(
          tar_blocks, tar_types_sizes
      ):
          if not blocks_line or not types_sizes_line:
              continue
  
          name = str(blocks_line[blocks_line.find(b":") + 2 :], "ascii")
          entry_type = types_sizes_line[0:1]
  
          if entry_type != b"-":
              continue
  
          offset = int(
              blocks_line[
                  blocks_line.find(b"block")
                  + 6 : blocks_line.find(b":")
              ]
          )
          # according to https://www.loc.gov/preservation/digital/formats/fdd/fdd000531.shtml#:~:text=A%20tar%20(tape%20archive)%20file,are%20not%20compressed%20archive%20files. # noqa: E501, W505
          # each data record is preceded by 512-byte header. `tar --list --block-num --file`
          # return the position (counted in 512-byte blocks) of the header for a given entry.
          # So the size of the header needs to be added to get the data offset
          offset = (offset + 1) * 512
  
          size = types_sizes_line[: -len(name)]
          size = size[
              : size.rfind(b"-") - 8
          ]  # "... <size> 20yy-mm-...."
          size = int(size[size.rfind(b" ") :])
  
          yield offset, name, size
  
file_path: DALI/tools/wds2idx.py
imports: import argparse
  import os
  import subprocess
  import sys
  import tarfile
  import time
  from shutil import which
label_desc: Use image node_id 8 for calling the IndexCreator obj's underlying member method code with example usage: obj._get_data_tar() without return types