A Python UPnP Media Server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
816 B

  1. #!/usr/bin/env python
  2. import tarfile
  3. from tarfile import *
  4. TAR_PLAIN = tarfile.TAR_PLAIN
  5. TAR_GZIPPED = tarfile.TAR_GZIPPED
  6. TAR_BZ2 = 'bz2'
  7. __all__ = tarfile.__all__
  8. class TarFileCompat(tarfile.TarFileCompat):
  9. def __init__(self, file, mode="r", compression=TAR_PLAIN):
  10. if compression != TAR_BZ2:
  11. tarfile.TarFileCompat.__init__(self, file, mode, compression)
  12. return
  13. self.tarfile = TarFile.bz2open(file, mode)
  14. if mode[0:1] == "r":
  15. members = self.tarfile.getmembers()
  16. for i in xrange(len(members)):
  17. m = members[i]
  18. m.filename = m.name
  19. m.file_size = m.size
  20. m.date_time = time.gmtime(m.mtime)[:6]
  21. def readiter(self, name, blksize=16384):
  22. f = self.tarfile.extractfile(self.tarfile.getmember(name))
  23. while True:
  24. data = f.read(blksize)
  25. if data == '':
  26. break
  27. yield data