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.

38 lines
913 B

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